diff --git a/bun.lock b/bun.lock index 20d3c41..8814932 100644 --- a/bun.lock +++ b/bun.lock @@ -17,6 +17,7 @@ "@tanstack/react-router-ssr-query": "^1.166.11", "@tanstack/react-start": "^1.167.43", "drizzle-orm": "0.45.2", + "drizzle-zod": "^0.8.3", "postgres": "^3.4.9", "react": "^19.2.5", "react-dom": "^19.2.5", @@ -445,6 +446,8 @@ "drizzle-orm": ["drizzle-orm@0.45.2", "", { "peerDependencies": { "@aws-sdk/client-rds-data": ">=3", "@cloudflare/workers-types": ">=4", "@electric-sql/pglite": ">=0.2.0", "@libsql/client": ">=0.10.0", "@libsql/client-wasm": ">=0.10.0", "@neondatabase/serverless": ">=0.10.0", "@op-engineering/op-sqlite": ">=2", "@opentelemetry/api": "^1.4.1", "@planetscale/database": ">=1.13", "@prisma/client": "*", "@tidbcloud/serverless": "*", "@types/better-sqlite3": "*", "@types/pg": "*", "@types/sql.js": "*", "@upstash/redis": ">=1.34.7", "@vercel/postgres": ">=0.8.0", "@xata.io/client": "*", "better-sqlite3": ">=7", "bun-types": "*", "expo-sqlite": ">=14.0.0", "gel": ">=2", "knex": "*", "kysely": "*", "mysql2": ">=2", "pg": ">=8", "postgres": ">=3", "sql.js": ">=1", "sqlite3": ">=5" }, "optionalPeers": ["@aws-sdk/client-rds-data", "@cloudflare/workers-types", "@electric-sql/pglite", "@libsql/client", "@libsql/client-wasm", "@neondatabase/serverless", "@op-engineering/op-sqlite", "@opentelemetry/api", "@planetscale/database", "@prisma/client", "@tidbcloud/serverless", "@types/better-sqlite3", "@types/pg", "@types/sql.js", "@upstash/redis", "@vercel/postgres", "@xata.io/client", "better-sqlite3", "bun-types", "expo-sqlite", "gel", "knex", "kysely", "mysql2", "pg", "postgres", "sql.js", "sqlite3"] }, "sha512-kY0BSaTNYWnoDMVoyY8uxmyHjpJW1geOmBMdSSicKo9CIIWkSxMIj2rkeSR51b8KAPB7m+qysjuHme5nKP+E5Q=="], + "drizzle-zod": ["drizzle-zod@0.8.3", "", { "peerDependencies": { "drizzle-orm": ">=0.36.0", "zod": "^3.25.0 || ^4.0.0" } }, "sha512-66yVOuvGhKJnTdiqj1/Xaaz9/qzOdRJADpDa68enqS6g3t0kpNkwNYjUuaeXgZfO/UWuIM9HIhSlJ6C5ZraMww=="], + "electron-to-chromium": ["electron-to-chromium@1.5.344", "", {}, "sha512-4MxfbmNDm+KPh066EZy+eUnkcDPcZ35wNmOWzFuh/ijvHsve6kbLTLURy88uCNK5FbpN+yk2nQY6BYh1GEt+wg=="], "encoding-sniffer": ["encoding-sniffer@0.2.1", "", { "dependencies": { "iconv-lite": "^0.6.3", "whatwg-encoding": "^3.1.1" } }, "sha512-5gvq20T6vfpekVtqrYQsSCFZ1wEg5+wW0/QaZMWkFr6BqD3NfKs0rLCx4rrVlSWJeZb5NBJgVLswK/w2MWU+Gw=="], diff --git a/drizzle/20260401114858_cultured_lady_mastermind/migration.sql b/drizzle/20260401114858_cultured_lady_mastermind/migration.sql deleted file mode 100644 index d2f00ae..0000000 --- a/drizzle/20260401114858_cultured_lady_mastermind/migration.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE "todo" ( - "id" uuid PRIMARY KEY, - "created_at" timestamp with time zone DEFAULT now() NOT NULL, - "updated_at" timestamp with time zone DEFAULT now() NOT NULL, - "title" text NOT NULL, - "completed" boolean DEFAULT false NOT NULL -); diff --git a/drizzle/20260401114858_cultured_lady_mastermind/snapshot.json b/drizzle/20260401114858_cultured_lady_mastermind/snapshot.json deleted file mode 100644 index fb368f0..0000000 --- a/drizzle/20260401114858_cultured_lady_mastermind/snapshot.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "version": "8", - "dialect": "postgres", - "id": "91ea16cc-3353-493c-bc2c-4fc9dea2fce7", - "prevIds": ["00000000-0000-0000-0000-000000000000"], - "ddl": [ - { - "isRlsEnabled": false, - "name": "todo", - "entityType": "tables", - "schema": "public" - }, - { - "type": "uuid", - "typeSchema": null, - "notNull": true, - "dimensions": 0, - "default": null, - "generated": null, - "identity": null, - "name": "id", - "entityType": "columns", - "schema": "public", - "table": "todo" - }, - { - "type": "timestamp with time zone", - "typeSchema": null, - "notNull": true, - "dimensions": 0, - "default": "now()", - "generated": null, - "identity": null, - "name": "created_at", - "entityType": "columns", - "schema": "public", - "table": "todo" - }, - { - "type": "timestamp with time zone", - "typeSchema": null, - "notNull": true, - "dimensions": 0, - "default": "now()", - "generated": null, - "identity": null, - "name": "updated_at", - "entityType": "columns", - "schema": "public", - "table": "todo" - }, - { - "type": "text", - "typeSchema": null, - "notNull": true, - "dimensions": 0, - "default": null, - "generated": null, - "identity": null, - "name": "title", - "entityType": "columns", - "schema": "public", - "table": "todo" - }, - { - "type": "boolean", - "typeSchema": null, - "notNull": true, - "dimensions": 0, - "default": "false", - "generated": null, - "identity": null, - "name": "completed", - "entityType": "columns", - "schema": "public", - "table": "todo" - }, - { - "columns": ["id"], - "nameExplicit": false, - "name": "todo_pkey", - "schema": "public", - "table": "todo", - "entityType": "pks" - } - ], - "renames": [] -} diff --git a/package.json b/package.json index f850aad..86e6303 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@tanstack/react-router-ssr-query": "^1.166.11", "@tanstack/react-start": "^1.167.43", "drizzle-orm": "0.45.2", + "drizzle-zod": "^0.8.3", "postgres": "^3.4.9", "react": "^19.2.5", "react-dom": "^19.2.5", diff --git a/src/server/api/contracts/todo.contract.ts b/src/server/api/contracts/todo.contract.ts index 8aed5cc..65a12dd 100644 --- a/src/server/api/contracts/todo.contract.ts +++ b/src/server/api/contracts/todo.contract.ts @@ -1,5 +1,5 @@ import { oc } from '@orpc/contract' -import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-orm/zod' +import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-zod' import { z } from 'zod' import { generatedFieldKeys } from '@/server/db/fields' import { todoTable } from '@/server/db/schema' diff --git a/src/server/api/routers/todo.router.ts b/src/server/api/routers/todo.router.ts index 523e999..36c450a 100644 --- a/src/server/api/routers/todo.router.ts +++ b/src/server/api/routers/todo.router.ts @@ -6,7 +6,7 @@ import { todoTable } from '@/server/db/schema' export const list = os.todo.list.use(db).handler(async ({ context }) => { const todos = await context.db.query.todoTable.findMany({ - orderBy: { createdAt: 'desc' }, + orderBy: (table, { desc }) => desc(table.createdAt), }) return todos }) diff --git a/src/server/db/index.ts b/src/server/db/index.ts index 21201f1..ea564c2 100644 --- a/src/server/db/index.ts +++ b/src/server/db/index.ts @@ -1,11 +1,11 @@ import { drizzle } from 'drizzle-orm/postgres-js' import { env } from '@/env' -import { relations } from '@/server/db/relations' +import * as schema from '@/server/db/schema' export const createDB = () => drizzle({ connection: env.DATABASE_URL, - relations, + schema, }) export type DB = ReturnType diff --git a/src/server/db/relations.ts b/src/server/db/relations.ts deleted file mode 100644 index 77b9f38..0000000 --- a/src/server/db/relations.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { defineRelations } from 'drizzle-orm' -import * as schema from './schema' - -export const relations = defineRelations(schema, (_r) => ({}))