Last active
May 2, 2025 13:16
-
-
Save JeanMeijer/1dff9ddb2c1734ba3b9e347322ceaea0 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