From 0c29fab6ea56ff58750c2b3cdd429b4242a8ab15 Mon Sep 17 00:00:00 2001 From: rvcas Date: Fri, 5 Apr 2024 21:39:23 -0400 Subject: [PATCH] chore: setup some weird db driver --- package.json | 3 + pnpm-lock.yaml | 168 +++++++++++++++++++++++++++- prisma/schema.prisma | 2 +- src/lib/server/dbsync.ts | 14 ++- src/routes/explorer/+page.server.ts | 2 - 5 files changed, 182 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7360503..bb05059 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0051fa0..19a191b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@dcspark/cardano-multiplatform-lib-nodejs': specifier: ^5.2.0 version: 5.2.0 + '@prisma/adapter-pg': + specifier: ^5.12.1 + version: 5.12.1(pg@8.11.5) '@prisma/client': specifier: ^5.12.1 version: 5.12.1(prisma@5.12.1) @@ -26,6 +29,9 @@ dependencies: layerchart: specifier: ^0.34.0 version: 0.34.0(postcss@8.4.35)(svelte@4.2.12)(typescript@5.3.3)(vite@5.2.8) + pg: + specifier: ^8.11.5 + version: 8.11.5 translucent-cardano: specifier: ^0.0.6 version: 0.0.6(typescript@5.3.3) @@ -70,6 +76,9 @@ devDependencies: '@types/node': specifier: ^20.11.24 version: 20.11.24 + '@types/pg': + specifier: ^8.11.4 + version: 8.11.4 '@types/ws': specifier: ^8.5.10 version: 8.5.10 @@ -1076,6 +1085,16 @@ packages: resolution: {integrity: sha512-2LuNTFBIO0m7kKIQvvPHN6UE63VjpmL9rnEEaOOaiSPbZK+zUOYIzBAWcED+3XYzhYsd/0mD57VdxAEqqV52CQ==} dev: true + /@prisma/adapter-pg@5.12.1(pg@8.11.5): + resolution: {integrity: sha512-WDBl3IJL0YyLCwXZPOpRnWqr/xS9RWFeBbSeo+z959DgbX6jrIYFdglvfFgAN0V9EWZGrt0as+t2aEROgrl+OA==} + peerDependencies: + pg: ^8.11.3 + dependencies: + '@prisma/driver-adapter-utils': 5.12.1 + pg: 8.11.5 + postgres-array: 3.0.2 + dev: false + /@prisma/client@5.12.1(prisma@5.12.1): resolution: {integrity: sha512-6/JnizEdlSBxDIdiLbrBdMW5NqDxOmhXAJaNXiPpgzAPr/nLZResT6MMpbOHLo5yAbQ1Vv5UU8PTPRzb0WIxdA==} engines: {node: '>=16.13'} @@ -1092,6 +1111,12 @@ packages: /@prisma/debug@5.12.1: resolution: {integrity: sha512-kd/wNsR0klrv79o1ITsbWxYyh4QWuBidvxsXSParPsYSu0ircUmNk3q4ojsgNc3/81b0ozg76iastOG43tbf8A==} + /@prisma/driver-adapter-utils@5.12.1: + resolution: {integrity: sha512-s5EHANHIyWID/3WLNYn3wy1SUGC2OFH2thYriq+sKo4GZxEduX9oraOVlPruZZBt/roN9ojZcph4R2oecWzfXg==} + dependencies: + '@prisma/debug': 5.12.1 + dev: false + /@prisma/engines-version@5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab: resolution: {integrity: sha512-6yvO8s80Tym61aB4QNtYZfWVmE3pwqe807jEtzm8C5VDe7nw8O1FGX3TXUaXmWV0fQTIAfRbeL2Gwrndabp/0g==} @@ -1579,6 +1604,14 @@ packages: dependencies: undici-types: 5.26.5 + /@types/pg@8.11.4: + resolution: {integrity: sha512-yw3Bwbda6vO+NvI1Ue/YKOwtl31AYvvd/e73O3V4ZkNzuGpTDndLSyc0dQRB2xrQqDePd20pEGIfqSp/GH3pRw==} + dependencies: + '@types/node': 20.11.24 + pg-protocol: 1.6.1 + pg-types: 4.0.2 + dev: true + /@types/pug@2.0.10: resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==} @@ -3869,6 +3902,10 @@ packages: object-keys: 1.1.1 dev: true + /obuf@1.1.2: + resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} + dev: true + /once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: @@ -4016,6 +4053,84 @@ packages: estree-walker: 3.0.3 is-reference: 3.0.2 + /pg-cloudflare@1.1.1: + resolution: {integrity: sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==} + requiresBuild: true + dev: false + optional: true + + /pg-connection-string@2.6.4: + resolution: {integrity: sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==} + dev: false + + /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'} + dev: true + + /pg-pool@3.6.2(pg@8.11.5): + resolution: {integrity: sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==} + peerDependencies: + pg: '>=8.0' + dependencies: + pg: 8.11.5 + dev: false + + /pg-protocol@1.6.1: + resolution: {integrity: sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==} + + /pg-types@2.2.0: + resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==} + engines: {node: '>=4'} + dependencies: + pg-int8: 1.0.1 + postgres-array: 2.0.0 + postgres-bytea: 1.0.0 + postgres-date: 1.0.7 + postgres-interval: 1.2.0 + dev: false + + /pg-types@4.0.2: + resolution: {integrity: sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==} + engines: {node: '>=10'} + dependencies: + pg-int8: 1.0.1 + pg-numeric: 1.0.2 + postgres-array: 3.0.2 + postgres-bytea: 3.0.0 + postgres-date: 2.1.0 + postgres-interval: 3.0.0 + postgres-range: 1.1.4 + dev: true + + /pg@8.11.5: + resolution: {integrity: sha512-jqgNHSKL5cbDjFlHyYsCXmQDrfIX/3RsNwYqpd4N0Kt8niLuNoRNH+aazv6cOd43gPh9Y4DjQCtb+X0MH0Hvnw==} + engines: {node: '>= 8.0.0'} + peerDependencies: + pg-native: '>=3.0.1' + peerDependenciesMeta: + pg-native: + optional: true + dependencies: + pg-connection-string: 2.6.4 + pg-pool: 3.6.2(pg@8.11.5) + pg-protocol: 1.6.1 + pg-types: 2.2.0 + pgpass: 1.0.5 + optionalDependencies: + pg-cloudflare: 1.1.1 + dev: false + + /pgpass@1.0.5: + resolution: {integrity: sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==} + dependencies: + split2: 4.2.0 + dev: false + /picocolors@1.0.0: resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} @@ -4173,6 +4288,53 @@ packages: picocolors: 1.0.0 source-map-js: 1.2.0 + /postgres-array@2.0.0: + resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==} + engines: {node: '>=4'} + dev: false + + /postgres-array@3.0.2: + resolution: {integrity: sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==} + engines: {node: '>=12'} + + /postgres-bytea@1.0.0: + resolution: {integrity: sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==} + engines: {node: '>=0.10.0'} + dev: false + + /postgres-bytea@3.0.0: + resolution: {integrity: sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==} + engines: {node: '>= 6'} + dependencies: + obuf: 1.1.2 + dev: true + + /postgres-date@1.0.7: + resolution: {integrity: sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==} + engines: {node: '>=0.10.0'} + dev: false + + /postgres-date@2.1.0: + resolution: {integrity: sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==} + engines: {node: '>=12'} + dev: true + + /postgres-interval@1.2.0: + resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} + engines: {node: '>=0.10.0'} + dependencies: + xtend: 4.0.2 + dev: false + + /postgres-interval@3.0.0: + resolution: {integrity: sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==} + engines: {node: '>=12'} + dev: true + + /postgres-range@1.1.4: + resolution: {integrity: sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==} + dev: true + /posthog-js@1.118.1: resolution: {integrity: sha512-3Ryk2XfdaUesAjrbruuRtY8QV8FEyUrwe95l1kiE+1XyMX0BHerCUFoc3kXcRZjbhhuaJP5i/jiIw8hLt+jHig==} dependencies: @@ -4645,6 +4807,11 @@ packages: deprecated: Please use @jridgewell/sourcemap-codec instead dev: true + /split2@4.2.0: + resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} + engines: {node: '>= 10.x'} + dev: false + /stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} dev: true @@ -5485,7 +5652,6 @@ packages: /xtend@4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} - dev: true /xxhash-wasm@1.0.2: resolution: {integrity: sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==} diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dd419a8..0cbf019 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,6 +1,6 @@ generator client { provider = "prisma-client-js" - previewFeatures = ["relationJoins"] + previewFeatures = ["relationJoins", "driverAdapters"] } datasource db { diff --git a/src/lib/server/dbsync.ts b/src/lib/server/dbsync.ts index f32ba0c..29a2c17 100644 --- a/src/lib/server/dbsync.ts +++ b/src/lib/server/dbsync.ts @@ -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; @@ -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; diff --git a/src/routes/explorer/+page.server.ts b/src/routes/explorer/+page.server.ts index 559dabc..38a6037 100644 --- a/src/routes/explorer/+page.server.ts +++ b/src/routes/explorer/+page.server.ts @@ -76,7 +76,5 @@ export async function load({ url }: PageServerLoadEvent) { | undefined, })); - console.log(blocks); - return { blocks, canNextPage, canPrevPage, totalPages, totalCount }; }