diff --git a/package-lock.json b/package-lock.json index 9f8f06f..43d0fea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "@fastify/cors": "^8.4.2", "@fastify/multipart": "^8.2.0", "@fastify/oauth2": "^7.8.0", - "@neondatabase/serverless": "^0.9.3", "drizzle-orm": "^0.31.1", "fastify": "^4.25.0", "fastify-plugin": "^4.5.1", @@ -991,6 +990,8 @@ "version": "0.9.3", "resolved": "https://registry.npmjs.org/@neondatabase/serverless/-/serverless-0.9.3.tgz", "integrity": "sha512-6ZBK8asl2Z3+ADEaELvbaVVGVlmY1oAzkxxZfpmXPKFuJhbDN+5fU3zYBamsahS/Ch1zE+CVWB3R+8QEI2LMSw==", + "optional": true, + "peer": true, "dependencies": { "@types/pg": "8.11.6" } @@ -1232,6 +1233,7 @@ "version": "8.11.6", "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.6.tgz", "integrity": "sha512-/2WmmBXHLsfRqzfHW7BNZ8SbYzE8OSk7i3WjFYvfgRHj7S1xj+16Je5fUKv3lVdVzk/zn9TXOqf+avFCFIE0yQ==", + "devOptional": true, "dependencies": { "@types/node": "*", "pg-protocol": "*", @@ -1242,6 +1244,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-4.0.1.tgz", "integrity": "sha512-hRCSDuLII9/LE3smys1hRHcu5QGcLs9ggT7I/TCs0IE+2Eesxi9+9RWAAwZ0yaGjxoWICF/YHLOEjydGujoJ+g==", + "devOptional": true, "license": "MIT", "dependencies": { "pg-int8": "1.0.1", @@ -1260,6 +1263,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.2.tgz", "integrity": "sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==", + "devOptional": true, "license": "MIT", "engines": { "node": ">=12" @@ -1269,6 +1273,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz", "integrity": "sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==", + "devOptional": true, "license": "MIT", "dependencies": { "obuf": "~1.1.2" @@ -1281,6 +1286,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.0.1.tgz", "integrity": "sha512-YtMKdsDt5Ojv1wQRvUhnyDJNSr2dGIC96mQVKz7xufp07nfuFONzdaowrMHjlAzY6GDLd4f+LUHHAAM1h4MdUw==", + "devOptional": true, "license": "MIT", "engines": { "node": ">=12" @@ -1290,6 +1296,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz", "integrity": "sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==", + "devOptional": true, "license": "MIT", "engines": { "node": ">=12" @@ -6838,6 +6845,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", "integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==", + "devOptional": true, "license": "MIT" }, "node_modules/on-exit-leak-free": { @@ -7128,6 +7136,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "devOptional": true, "license": "ISC", "engines": { "node": ">=4.0.0" @@ -7137,6 +7146,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz", "integrity": "sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==", + "devOptional": true, "license": "ISC", "engines": { "node": ">=4" @@ -7154,7 +7164,8 @@ "node_modules/pg-protocol": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.1.tgz", - "integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==" + "integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==", + "devOptional": true }, "node_modules/pg-types": { "version": "2.2.0", @@ -7337,6 +7348,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.3.tgz", "integrity": "sha512-VdlZoocy5lCP0c/t66xAfclglEapXPCIVhqqJRncYpvbCgImF0w67aPKfbqUMr72tO2k5q0TdTZwCLjPTI6C9g==", + "devOptional": true, "license": "MIT" }, "node_modules/prelude-ls": { diff --git a/package.json b/package.json index be6faf9..592cb4f 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "@fastify/cors": "^8.4.2", "@fastify/multipart": "^8.2.0", "@fastify/oauth2": "^7.8.0", - "@neondatabase/serverless": "^0.9.3", "drizzle-orm": "^0.31.1", "fastify": "^4.25.0", "fastify-plugin": "^4.5.1", diff --git a/src/db/index.js b/src/db/index.js index f04efd0..3630cbd 100644 --- a/src/db/index.js +++ b/src/db/index.js @@ -2,14 +2,22 @@ import * as schema from "./schemas.js"; import { env, Logger } from "../utils/index.js"; import { drizzle } from "drizzle-orm/node-postgres"; import { migrate } from "drizzle-orm/node-postgres/migrator"; -import { neon } from '@neondatabase/serverless'; - +import pgpkg from 'pg'; +const { Pool } = pgpkg; /** @type {ReturnType>} */ export let db; export const initDb = async () => { - const client = neon(env.DATABASE_URL); + const client = new Pool({ + connectionString: env.DATABASE_URL, + ssl: false, + idleTimeoutMillis: 0, + connectionTimeoutMillis: 0, + keepAlive: true + }); + + await client.connect(); db = drizzle(client, { schema, diff --git a/yarn.lock b/yarn.lock index 07123fd..e2dd71c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -265,7 +265,7 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@neondatabase/serverless@^0.9.3", "@neondatabase/serverless@>=0.1": +"@neondatabase/serverless@>=0.1": version "0.9.3" resolved "https://registry.npmjs.org/@neondatabase/serverless/-/serverless-0.9.3.tgz" integrity sha512-6ZBK8asl2Z3+ADEaELvbaVVGVlmY1oAzkxxZfpmXPKFuJhbDN+5fU3zYBamsahS/Ch1zE+CVWB3R+8QEI2LMSw==