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 0e1e69b commit 0c29fab
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 7 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@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 @@ -58,12 +59,14 @@
"type": "module",
"dependencies": {
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.2.0",
"@prisma/adapter-pg": "^5.12.1",
"@prisma/client": "^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
168 changes: 167 additions & 1 deletion pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["relationJoins"]
previewFeatures = ["relationJoins", "driverAdapters"]
}

datasource db {
Expand Down
14 changes: 11 additions & 3 deletions src/lib/server/dbsync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import pg from 'pg';

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

let dbsync: PrismaClient;

Expand All @@ -13,10 +15,16 @@ 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') {
dbsync = new PrismaClient();
const pool = new pg.Pool({ connectionString: DATABASE_URL });
const adapter = new PrismaPg(pool);

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

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

dbsync = global.__dbsync;
Expand Down
2 changes: 0 additions & 2 deletions src/routes/explorer/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,5 @@ export async function load({ url }: PageServerLoadEvent) {
| undefined,
}));

console.log(blocks);

return { blocks, canNextPage, canPrevPage, totalPages, totalCount };
}

0 comments on commit 0c29fab

Please sign in to comment.