-
-
Save lassejlv/5c45a4a48746506456dd327786f4d657 to your computer and use it in GitHub Desktop.
Type-safe messages with Vercel AI SDK and Drizzle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { pgTable, json, text, timestamp } from "drizzle-orm/pg-core"; | |
import type { Message, Attachment } from "ai"; | |
export const message = pgTable("message", { | |
id: text("id").primaryKey(), | |
chatId: text("chatId") | |
.notNull() | |
.references(() => chat.id), | |
// infers: "data" | "user" | "system" | "assistant" | |
role: text("role", { enum: ["data", "user", "system", "assistant"]}).notNull(), | |
// infers: (TextUIPart | ReasoningUIPart | .... )[] | undefined | |
parts: json("parts").notNull().$type<Message["parts"]>(), | |
content: text("content").notNull(), | |
attachments: json("attachments").notNull().$type<Attachment[]>(), | |
createdAt: timestamp("createdAt").defaultNow().notNull(), | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment