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
| 1 | import { defineContract } from "@alchemy.run/prisma/ORM"; |
| 2 | |
| 3 | export const contract = defineContract( |
| 4 | { extensions: {}, foreignKeyDefaults: { constraint: true, index: true } }, |
| 5 | ({ field, model, rel }) => { |
| 6 | const User = model("User", { |
| 7 | fields: { |
| 8 | id: field.int().id().default({ kind: "function", expression: "autoincrement()" }), |
| 9 | email: field.text().unique(), |
| 10 | name: field.text().optional(), |
| 11 | }, |
| 12 | }).sql({ table: "user" }); |
| 13 | const Post = model("Post", { |
| 14 | fields: { |
| 15 | id: field.int().id().default({ kind: "function", expression: "autoincrement()" }), |
| 16 | title: field.text(), |
| 17 | authorId: field.int(), |
| 18 | }, |
| 19 | relations: { |
| 20 | author: rel.belongsTo(User, { from: "authorId", to: "id" }).sql({ |
| 21 | fk: { constraint: true, index: true }, |
| 22 | }), |
| 23 | }, |
| 24 | }).sql({ table: "post" }); |
| 25 | return { |
| 26 | models: { |
| 27 | User: User.relations({ posts: rel.hasMany(Post, { by: "authorId" }) }), |
| 28 | Post, |
| 29 | }, |
| 30 | }; |
| 31 | }, |
| 32 | ); |