11import test from 'ava' ;
22import {
3- Pool ,
3+ Pool as PgPool ,
44} from 'pg' ;
55import postgres from 'postgres' ;
66import * as sinon from 'sinon' ;
77import {
88 createBridge ,
99} from '../../src/bridge' ;
1010
11+ const PostgresBridge = createBridge ( postgres ) ;
12+
1113const clients = [
12- 'pg' ,
13- 'postgres' ,
14+ {
15+ name : 'pg' ,
16+ Pool : PgPool ,
17+ } ,
18+ {
19+ name : 'postgres-bridge' ,
20+ Pool : PostgresBridge ,
21+ } ,
1422] ;
1523
16- const createPool = ( clientName : string , poolConfiguration ) => {
17- if ( clientName === 'pg' ) {
18- return new Pool ( poolConfiguration ) ;
19- }
20-
21- const PostgresBridge = createBridge ( postgres ) ;
22-
23- return new PostgresBridge ( {
24- ...poolConfiguration ,
25- } ) ;
26- } ;
27-
28- for ( const client of clients ) {
29- test ( client + ': "connect" event is fired when a new connection is made' , async ( t ) => {
30- const pool = createPool ( client , {
24+ for ( const {
25+ name : clientName ,
26+ Pool,
27+ } of clients ) {
28+ test ( clientName + ': "connect" event is fired when a new connection is made' , async ( t ) => {
29+ const pool = new Pool ( {
3130 user : 'postgres' ,
3231 } ) ;
3332
@@ -42,8 +41,8 @@ for (const client of clients) {
4241 t . is ( spy . firstCall . args [ 0 ] , connection ) ;
4342 } ) ;
4443
45- test ( client + ': "notice event is fired when connection produces a notice"' , async ( t ) => {
46- const pool = createPool ( client , {
44+ test ( clientName + ': "notice event is fired when connection produces a notice"' , async ( t ) => {
45+ const pool = new Pool ( {
4746 user : 'postgres' ,
4847 } ) ;
4948
@@ -58,7 +57,7 @@ for (const client of clients) {
5857 DECLARE
5958 a INT:= 10;
6059 BEGIN
61- RAISE NOTICE 'value of a: %', a;
60+ RAISE NOTICE 'value of a: %', a;
6261 END;
6362 $$
6463 LANGUAGE plpgsql;
@@ -81,8 +80,8 @@ for (const client of clients) {
8180 } ) ;
8281 } ) ;
8382
84- test ( client + ': pool.connect() 2x creates two connections' , async ( t ) => {
85- const pool = createPool ( client , {
83+ test ( clientName + ': pool.connect() 2x creates two connections' , async ( t ) => {
84+ const pool = new Pool ( {
8685 user : 'postgres' ,
8786 } ) ;
8887
@@ -97,8 +96,8 @@ for (const client of clients) {
9796 await connection2 . end ( ) ;
9897 } ) ;
9998
100- test ( client + ': connection.release() releases connection back to the pool' , async ( t ) => {
101- const pool = createPool ( client , {
99+ test ( clientName + ': connection.release() releases connection back to the pool' , async ( t ) => {
100+ const pool = new Pool ( {
102101 user : 'postgres' ,
103102 } ) ;
104103
@@ -111,8 +110,8 @@ for (const client of clients) {
111110 t . is ( pool . idleCount , 1 ) ;
112111 } ) ;
113112
114- test ( client + ': query method' , async ( t ) => {
115- const pool = createPool ( client , {
113+ test ( clientName + ': query method' , async ( t ) => {
114+ const pool = new Pool ( {
116115 user : 'postgres' ,
117116 } ) ;
118117
@@ -133,8 +132,8 @@ for (const client of clients) {
133132 } ) ;
134133 } ) ;
135134
136- test ( client + ': query method with parameters' , async ( t ) => {
137- const pool = createPool ( client , {
135+ test ( clientName + ': query method with parameters' , async ( t ) => {
136+ const pool = new Pool ( {
138137 user : 'postgres' ,
139138 } ) ;
140139
@@ -157,8 +156,8 @@ for (const client of clients) {
157156 } ) ;
158157 } ) ;
159158
160- test ( client + ': _clients returns all active connections' , async ( t ) => {
161- const pool = createPool ( client , {
159+ test ( clientName + ': _clients returns all active connections' , async ( t ) => {
160+ const pool = new Pool ( {
162161 user : 'postgres' ,
163162 } ) ;
164163
0 commit comments