@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 37 lines 1.07 KB
Raw
1 import { defineRelations, sql } 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 email: text("email").notNull().unique(),
7 name: text("name").notNull(),
8 createdAt: integer("created_at", { mode: "timestamp" })
9 .notNull()
10 .default(sql`(unixepoch())`),
11 });
12 export type User = typeof Users.$inferSelect;
13
14 export const Posts = sqliteTable("posts", {
15 id: integer("id").primaryKey({ autoIncrement: true }),
16 userId: integer("user_id")
17 .notNull()
18 .references(() => Users.id, { onDelete: "cascade" }),
19 title: text("title").notNull(),
20 body: text("body").notNull(),
21 createdAt: integer("created_at", { mode: "timestamp" })
22 .notNull()
23 .default(sql`(unixepoch())`),
24 });
25 export type Post = typeof Posts.$inferSelect;
26
27 export const relations = defineRelations({ Users, Posts }, (t) => ({
28 Users: {
29 posts: t.many.Posts(),
30 },
31 Posts: {
32 user: t.one.Users({
33 from: t.Posts.userId,
34 to: t.Users.id,
35 }),
36 },
37 }));