diff --git a/package.json b/package.json index 0ce2b24..1781c17 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { + "@neondatabase/serverless": "^1.0.0", "@t3-oss/env-nextjs": "^0.12.0", "drizzle-orm": "^0.41.0", "next": "^15.2.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ac4015..ecb4e3e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,15 @@ importers: .: dependencies: + '@neondatabase/serverless': + specifier: ^1.0.0 + version: 1.0.0 '@t3-oss/env-nextjs': specifier: ^0.12.0 version: 0.12.0(typescript@5.8.3)(zod@3.24.2) drizzle-orm: specifier: ^0.41.0 - version: 0.41.0(gel@2.0.2)(postgres@3.4.5) + version: 0.41.0(@neondatabase/serverless@1.0.0)(@types/pg@8.11.11)(gel@2.0.2)(postgres@3.4.5) next: specifier: ^15.2.3 version: 15.2.4(react-dom@19.1.0(react@19.1.0))(react@19.1.0) @@ -506,6 +509,10 @@ packages: cpu: [x64] os: [win32] + '@neondatabase/serverless@1.0.0': + resolution: {integrity: sha512-XWmEeWpBXIoksZSDN74kftfTnXFEGZ3iX8jbANWBc+ag6dsiQuvuR4LgB0WdCOKMb5AQgjqgufc0TgAsZubUYw==} + engines: {node: '>=19.0.0'} + '@next/env@15.2.4': resolution: {integrity: sha512-+SFtMgoiYP3WoSswuNmxJOCwi06TdWE733D+WPjpXIe4LXGULwEaofiiAy6kbS0+XjM5xF5n3lKuBwN2SnqD9g==} @@ -673,6 +680,12 @@ packages: '@types/node@20.17.30': resolution: {integrity: sha512-7zf4YyHA+jvBNfVrk2Gtvs6x7E8V+YDW05bNfG2XkWDJfYRXrTiP/DsB2zSYTaHX0bGIujTBQdMVAhb+j7mwpg==} + '@types/node@22.14.0': + resolution: {integrity: sha512-Kmpl+z84ILoG+3T/zQFyAJsU6EPTmOCj8/2+83fSN6djd6I4o7uOuGIH6vq3PrjY5BGitSbFuMN18j3iknubbA==} + + '@types/pg@8.11.11': + resolution: {integrity: sha512-kGT1qKM8wJQ5qlawUrEkXgvMSXoV213KfMGXcwfDwUIfUHXqXYXOfS1nE1LINRJVVVx5wCm70XnFlMHaIcQAfw==} + '@types/react-dom@19.1.1': resolution: {integrity: sha512-jFf/woGTVTjUJsl2O7hcopJ1r0upqoq/vIOoCj0yLh3RIXxWcljlpuZ+vEBRXsymD1jhfeJrlyTy/S1UW+4y1w==} peerDependencies: @@ -955,6 +968,24 @@ packages: sass: optional: true + obuf@1.1.2: + resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} + + pg-int8@1.0.1: + resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==} + engines: {node: '>=4.0.0'} + + pg-numeric@1.0.2: + resolution: {integrity: sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==} + engines: {node: '>=4'} + + pg-protocol@1.8.0: + resolution: {integrity: sha512-jvuYlEkL03NRvOoyoRktBK7+qU5kOvlAwvmrH8sr3wbLrOdVWsRxQfz8mMy9sZFsqJ1hEWNfdWKI4SAmoL+j7g==} + + pg-types@4.0.2: + resolution: {integrity: sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==} + engines: {node: '>=10'} + picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -966,6 +997,25 @@ packages: resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==} engines: {node: ^10 || ^12 || >=14} + postgres-array@3.0.4: + resolution: {integrity: sha512-nAUSGfSDGOaOAEGwqsRY27GPOea7CNipJPOA7lPbdEpx5Kg3qzdP0AaWC5MlhTWV9s4hFX39nomVZ+C4tnGOJQ==} + engines: {node: '>=12'} + + postgres-bytea@3.0.0: + resolution: {integrity: sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==} + engines: {node: '>= 6'} + + postgres-date@2.1.0: + resolution: {integrity: sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==} + engines: {node: '>=12'} + + postgres-interval@3.0.0: + resolution: {integrity: sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==} + engines: {node: '>=12'} + + postgres-range@1.1.4: + resolution: {integrity: sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==} + postgres@3.4.5: resolution: {integrity: sha512-cDWgoah1Gez9rN3H4165peY9qfpEo+SA61oQv65O3cRUE1pOEoJWwddwcqKE8XZYjbblOJlYDlLV4h67HrEVDg==} engines: {node: '>=12'} @@ -1047,6 +1097,9 @@ packages: undici-types@6.19.8: resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} + which@4.0.0: resolution: {integrity: sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==} engines: {node: ^16.13.0 || >=18.0.0} @@ -1321,6 +1374,11 @@ snapshots: '@img/sharp-win32-x64@0.33.5': optional: true + '@neondatabase/serverless@1.0.0': + dependencies: + '@types/node': 22.14.0 + '@types/pg': 8.11.11 + '@next/env@15.2.4': {} '@next/swc-darwin-arm64@15.2.4': @@ -1433,6 +1491,16 @@ snapshots: dependencies: undici-types: 6.19.8 + '@types/node@22.14.0': + dependencies: + undici-types: 6.21.0 + + '@types/pg@8.11.11': + dependencies: + '@types/node': 20.17.30 + pg-protocol: 1.8.0 + pg-types: 4.0.2 + '@types/react-dom@19.1.1(@types/react@19.1.0)': dependencies: '@types/react': 19.1.0 @@ -1489,8 +1557,10 @@ snapshots: transitivePeerDependencies: - supports-color - drizzle-orm@0.41.0(gel@2.0.2)(postgres@3.4.5): + drizzle-orm@0.41.0(@neondatabase/serverless@1.0.0)(@types/pg@8.11.11)(gel@2.0.2)(postgres@3.4.5): optionalDependencies: + '@neondatabase/serverless': 1.0.0 + '@types/pg': 8.11.11 gel: 2.0.2 postgres: 3.4.5 @@ -1657,6 +1727,24 @@ snapshots: - '@babel/core' - babel-plugin-macros + obuf@1.1.2: {} + + pg-int8@1.0.1: {} + + pg-numeric@1.0.2: {} + + pg-protocol@1.8.0: {} + + pg-types@4.0.2: + dependencies: + pg-int8: 1.0.1 + pg-numeric: 1.0.2 + postgres-array: 3.0.4 + postgres-bytea: 3.0.0 + postgres-date: 2.1.0 + postgres-interval: 3.0.0 + postgres-range: 1.1.4 + picocolors@1.1.1: {} postcss@8.4.31: @@ -1671,6 +1759,18 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 + postgres-array@3.0.4: {} + + postgres-bytea@3.0.0: + dependencies: + obuf: 1.1.2 + + postgres-date@2.1.0: {} + + postgres-interval@3.0.0: {} + + postgres-range@1.1.4: {} + postgres@3.4.5: {} react-dom@19.1.0(react@19.1.0): @@ -1746,6 +1846,8 @@ snapshots: undici-types@6.19.8: {} + undici-types@6.21.0: {} + which@4.0.0: dependencies: isexe: 3.1.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..1fab73a --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,4 @@ +ignoredBuiltDependencies: + - '@biomejs/biome' + - esbuild + - sharp diff --git a/src/server/db/index.ts b/src/server/db/index.ts index df18baf..c6552ee 100644 --- a/src/server/db/index.ts +++ b/src/server/db/index.ts @@ -1,18 +1,31 @@ -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; +// import { drizzle } from "drizzle-orm/postgres-js"; +// import postgres from "postgres"; import { env } from "~/env"; import * as schema from "./schema"; -/** - * Cache the database connection in development. This avoids creating a new connection on every HMR - * update. - */ -const globalForDb = globalThis as unknown as { - conn: postgres.Sql | undefined; -}; +// /** +// * Cache the database connection in development. This avoids creating a new connection on every HMR +// * update. +// */ +// const globalForDb = globalThis as unknown as { +// conn: postgres.Sql | undefined; +// }; -const conn = globalForDb.conn ?? postgres(env.DATABASE_URL); -if (env.NODE_ENV !== "production") globalForDb.conn = conn; +// const conn = globalForDb.conn ?? postgres(env.DATABASE_URL); +// if (env.NODE_ENV !== "production") globalForDb.conn = conn; -export const db = drizzle(conn, { schema }); +// export const db = drizzle(conn, { schema }); + + +// ========== vercel snippet ================= + +import { drizzle } from "drizzle-orm/neon-http"; +import { neon } from "@neondatabase/serverless"; +// import { config } from "dotenv"; + +// config({ path: ".env" }); // or .env.local + +// const sql = neon(process.env.DATABASE_URL!); +const sql = neon(env.DATABASE_URL!); +export const db = drizzle({ client: sql,schema: schema });