Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/package-lock.json

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

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/pongo-core",
"version": "0.6.1",
"version": "0.7.0",
"description": "Pongo - Mongo with strong consistency on top of Postgres",
"type": "module",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/pongo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/pongo",
"version": "0.6.1",
"version": "0.7.0",
"description": "Pongo - Mongo with strong consistency on top of Postgres",
"type": "module",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions src/packages/pongo/src/main/pongoClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { getDatabaseNameOrDefault } from '@event-driven-io/dumbo';
import pg from 'pg';
import { getDbClient, type DbClient } from './dbClient';
import type { PongoClient, PongoDb } from './typing/operations';

export const pongoClient = (connectionString: string): PongoClient => {
export const pongoClient = (
connectionString: string,
options: { client?: pg.PoolClient } = {},
): PongoClient => {
const defaultDbName = getDatabaseNameOrDefault(connectionString);
const dbClients: Map<string, DbClient> = new Map();

const dbClient = getDbClient({ connectionString });
const dbClient = getDbClient({ connectionString, client: options.client });
dbClients.set(defaultDbName, dbClient);

const pongoClient: PongoClient = {
Expand All @@ -25,7 +29,14 @@ export const pongoClient = (connectionString: string): PongoClient => {
return (
dbClients.get(dbName) ??
dbClients
.set(dbName, getDbClient({ connectionString, dbName: dbName }))
.set(
dbName,
getDbClient({
connectionString,
dbName: dbName,
client: options.client,
}),
)
.get(dbName)!
);
},
Expand Down
8 changes: 6 additions & 2 deletions src/packages/pongo/src/mongo/mongoClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// src/MongoClientShim.ts
import pg from 'pg';
import { pongoClient, type PongoClient } from '../main';
import { Db } from './mongoDb';

export class MongoClient {
private pongoClient: PongoClient;

constructor(connectionString: string) {
this.pongoClient = pongoClient(connectionString);
constructor(
connectionString: string,
options: { client?: pg.PoolClient } = {},
) {
this.pongoClient = pongoClient(connectionString, options);
}

async connect() {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/pongo/src/postgres/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { postgresCollection } from './postgresCollection';
export type PongoClientOptions = {
connectionString: string;
dbName?: string | undefined;
client?: pg.PoolClient;
client?: pg.PoolClient | undefined;
};

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