gajus / slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
Other
4.56k stars 138 forks source link

README doesn't properly demonstrate `postgres-bridge` integration #623

Open ravinggenius opened 3 months ago

ravinggenius commented 3 months ago

Expected Behavior

Following instructions in the README, I should be able to integrate with postgres-bridge.

Current Behavior

Following the example in the README causes confusion, as PgPool isn't a valid configuration key. I get the following TypeScript error: "Object literal may only specify known properties, and 'PgPool' does not exist in type 'Partial. ts(2353)". Furthermore the README for postgres-bridge shows a different way to use it, but not with slonik specifically (as far as I can tell).

Possible Solution

Please show a working example of integrating postgres-bridge with a project that uses slonik.

Steps to Reproduce

  1. checkout my project: https://github.com/ravinggenius/minecraft-tools
  2. install postgres and postgres-bridge
  3. open the file src/services/datastore-service.ts
  4. apply the following diff:
diff --git a/src/services/datastore-service.ts b/src/services/datastore-service.ts
index 32e5716..e176812 100644
--- a/src/services/datastore-service.ts
+++ b/src/services/datastore-service.ts
@@ -1,4 +1,6 @@
 import trim from "cool-trim";
+import postgres from "postgres";
+import { createPostgresBridge } from "postgres-bridge";
 import { createPool, Interceptor, sql } from "slonik";
 import { createQueryLoggingInterceptor } from "slonik-interceptor-query-logging";
 import { createQueryNormalisationInterceptor } from "slonik-interceptor-query-normalisation";
@@ -21,7 +23,8 @@ export const pool = createPool(config.databaseUrl, {
            ? createQueryNormalisationInterceptor()
            : createQueryTrimInterceptor(),
        createQueryLoggingInterceptor()
-   ]
+   ],
+   PgPool: createPostgresBridge(postgres)
 });

 export { sql };

Logs

N/A