1import { defineRelations } from "drizzle-orm";
2import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
4export const users = sqliteTable("users", {
5 id: integer("id").primaryKey({ autoIncrement: true }),
6 name: text("name").notNull(),
7});
8
9export 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
17export 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}));