-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to inject PoolClient to PongoClient
That will enable running transactions and sharing connection with Emmett projections
- Loading branch information
1 parent
27669bd
commit de94c41
Showing
5 changed files
with
23 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './client'; | ||
export * from './dbClient'; | ||
export * from './pongoClient'; | ||
export * from './typing'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { endPool, getPool } from '@event-driven-io/dumbo'; | ||
import pg from 'pg'; | ||
import { type DbClient } from '../main'; | ||
import { postgresCollection } from './postgresCollection'; | ||
|
||
export const postgresClient = ( | ||
connectionString: string, | ||
database?: string, | ||
): DbClient => { | ||
const pool = getPool({ connectionString, database }); | ||
export type PongoClientOptions = { | ||
connectionString: string; | ||
database?: string | undefined; | ||
client?: pg.PoolClient; | ||
}; | ||
|
||
export const postgresClient = (options: PongoClientOptions): DbClient => { | ||
const { connectionString, database, client } = options; | ||
const managesPoolLifetime = !client; | ||
const clientOrPool = client ?? getPool({ connectionString, database }); | ||
|
||
return { | ||
connect: () => Promise.resolve(), | ||
close: () => endPool({ connectionString, database }), | ||
collection: <T>(name: string) => postgresCollection<T>(name, pool), | ||
close: () => | ||
managesPoolLifetime | ||
? endPool({ connectionString, database }) | ||
: Promise.resolve(), | ||
collection: <T>(name: string) => postgresCollection<T>(name, clientOrPool), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters