Skip to content

Commit

Permalink
chore: setup some weird db driver
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Apr 6, 2024
1 parent 0c29fab commit 9a3bdce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 104 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@types/d3-shape": "^3.1.6",
"@types/eslint": "^8.56.0",
"@types/node": "^20.11.24",
"@types/pg": "^8.11.4",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
Expand Down Expand Up @@ -59,14 +58,14 @@
"type": "module",
"dependencies": {
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.2.0",
"@prisma/adapter-pg": "^5.12.1",
"@prisma/adapter-pg-worker": "^5.12.1",
"@prisma/client": "^5.12.1",
"@prisma/pg-worker": "^5.12.1",
"d3-array": "^3.2.4",
"d3-scale": "^4.0.2",
"d3-shape": "^3.2.0",
"date-fns": "^3.6.0",
"layerchart": "^0.34.0",
"pg": "^8.11.5",
"translucent-cardano": "^0.0.6",
"ws": "^8.16.0"
}
Expand Down
115 changes: 21 additions & 94 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/lib/server/dbsync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import pg from 'pg';
import { PrismaPg } from '@prisma/adapter-pg-worker';
import { Pool } from '@prisma/pg-worker';

import { NODE_ENV, DATABASE_URL } from '$env/static/private';

Expand All @@ -15,16 +15,13 @@ declare global {
// the server with every change, but we want to make sure we don't
// create a new connection to the DB with every change either.
if (NODE_ENV === 'production') {
const pool = new pg.Pool({ connectionString: DATABASE_URL });
const pool = new Pool({ connectionString: DATABASE_URL });
const adapter = new PrismaPg(pool);

dbsync = new PrismaClient({ adapter });
} else {
if (!global.__dbsync) {
const pool = new pg.Pool({ connectionString: DATABASE_URL });
const adapter = new PrismaPg(pool);

global.__dbsync = new PrismaClient({ adapter, log: ['query'] });
global.__dbsync = new PrismaClient({ log: ['query'] });
}

dbsync = global.__dbsync;
Expand Down

0 comments on commit 9a3bdce

Please sign in to comment.