| 1 | import { defineRelations } from "drizzle-orm"; |
| 2 | import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; |
| 3 | |
| 4 | export const users = sqliteTable("users", { |
| 5 | id: integer("id").primaryKey({ autoIncrement: true }), |
| 6 | name: text("name").notNull(), |
| 7 | }); |
| 8 | |
| 9 | export const posts = sqliteTable("posts", { |
| 10 | id: integer("id").primaryKey({ autoIncrement: true }), |
| 11 | userId: integer("user_id") |
| 12 | .notNull() |
| 13 | .references(() => users.id), |
| 14 | title: text("title").notNull(), |
| 15 | }); |
| 16 | |
| 17 | export const relations = defineRelations({ users, posts }, (t) => ({ |
| 18 | users: { posts: t.many.posts() }, |
| 19 | posts: { |
| 20 | author: t.one.users({ from: t.posts.userId, to: t.users.id }), |
| 21 | }, |
| 22 | })); |