Skip to content

Commit 4da27f8

Browse files
committed
Exposed option to inject pg.PoolClient
It seems that it was exposed in postgresClient but not in the final poolClient
1 parent c151455 commit 4da27f8

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

src/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo-core",
3-
"version": "0.6.1",
3+
"version": "0.7.0",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"engines": {

src/packages/pongo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo",
3-
"version": "0.6.1",
3+
"version": "0.7.0",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"scripts": {

src/packages/pongo/src/main/pongoClient.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { getDatabaseNameOrDefault } from '@event-driven-io/dumbo';
2+
import pg from 'pg';
23
import { getDbClient, type DbClient } from './dbClient';
34
import type { PongoClient, PongoDb } from './typing/operations';
45

5-
export const pongoClient = (connectionString: string): PongoClient => {
6+
export const pongoClient = (
7+
connectionString: string,
8+
options: { client?: pg.PoolClient } = {},
9+
): PongoClient => {
610
const defaultDbName = getDatabaseNameOrDefault(connectionString);
711
const dbClients: Map<string, DbClient> = new Map();
812

9-
const dbClient = getDbClient({ connectionString });
13+
const dbClient = getDbClient({ connectionString, client: options.client });
1014
dbClients.set(defaultDbName, dbClient);
1115

1216
const pongoClient: PongoClient = {
@@ -25,7 +29,14 @@ export const pongoClient = (connectionString: string): PongoClient => {
2529
return (
2630
dbClients.get(dbName) ??
2731
dbClients
28-
.set(dbName, getDbClient({ connectionString, dbName: dbName }))
32+
.set(
33+
dbName,
34+
getDbClient({
35+
connectionString,
36+
dbName: dbName,
37+
client: options.client,
38+
}),
39+
)
2940
.get(dbName)!
3041
);
3142
},

src/packages/pongo/src/mongo/mongoClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// src/MongoClientShim.ts
2+
import pg from 'pg';
23
import { pongoClient, type PongoClient } from '../main';
34
import { Db } from './mongoDb';
45

56
export class MongoClient {
67
private pongoClient: PongoClient;
78

8-
constructor(connectionString: string) {
9-
this.pongoClient = pongoClient(connectionString);
9+
constructor(
10+
connectionString: string,
11+
options: { client?: pg.PoolClient } = {},
12+
) {
13+
this.pongoClient = pongoClient(connectionString, options);
1014
}
1115

1216
async connect() {

src/packages/pongo/src/postgres/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { postgresCollection } from './postgresCollection';
1010
export type PongoClientOptions = {
1111
connectionString: string;
1212
dbName?: string | undefined;
13-
client?: pg.PoolClient;
13+
client?: pg.PoolClient | undefined;
1414
};
1515

1616
export const postgresClient = (options: PongoClientOptions): DbClient => {

0 commit comments

Comments
 (0)