chatbot-template/lib/db/schema.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-06-02 11:15:04 -04:00
import { sql } from "@vercel/postgres";
2023-06-02 11:33:17 -04:00
import { pgTable, text } from "drizzle-orm/pg-core";
2023-06-02 11:15:04 -04:00
import { drizzle } from "drizzle-orm/vercel-postgres";
2023-05-22 12:14:37 -04:00
2023-06-02 11:15:04 -04:00
// const connection = createPool({ connectionString: process.env.POSTGRES_URL });
export const chats = pgTable("chats", {
id: text("id").notNull().primaryKey(),
title: text("role").notNull(),
2023-06-02 11:33:17 -04:00
userId: text("userId").notNull(),
// messages: json("messages").notNull().default({}),
// .references(() => users.id),
2023-06-02 11:15:04 -04:00
});
2023-06-02 11:33:17 -04:00
// export const messages = pgTable("messages", {
// id: text("id").notNull().primaryKey(),
// title: text("role").notNull(),
// chatId: text("chatId")
// .notNull()
// .references(() => chats.id),
// });
// export const chatsRelations = relations(chats, ({ many }) => ({
// // user: one(users, {
// // fields: [chats.userId],
// // references: [users.id],
// // }),
// messages: many(messages),
// }));
// export const messagesRelations = relations(messages, ({ one }) => ({
// chat: one(chats, {
// fields: [messages.chatId],
// references: [chats.id],
// }),
// }));
2023-06-02 11:15:04 -04:00
export const db = drizzle(sql, {
schema: {
2023-06-02 11:33:17 -04:00
// users,
// accounts,
// sessions,
// verificationTokens,
2023-06-02 11:15:04 -04:00
chats,
2023-06-02 11:33:17 -04:00
// chatsRelations,
// messages,
// messagesRelations,
// usersRelations,
2023-06-02 11:15:04 -04:00
},
});
2023-05-22 12:14:37 -04:00
2023-06-02 11:15:04 -04:00
export type DbClient = typeof db;
2023-06-02 11:33:17 -04:00
export type Schema = {
chats: typeof chats;
};