1
1
import test from 'ava' ;
2
2
import {
3
- Pool ,
3
+ Pool as PgPool ,
4
4
} from 'pg' ;
5
5
import postgres from 'postgres' ;
6
6
import * as sinon from 'sinon' ;
7
7
import {
8
8
createBridge ,
9
9
} from '../../src/bridge' ;
10
10
11
+ const PostgresBridge = createBridge ( postgres ) ;
12
+
11
13
const clients = [
12
- 'pg' ,
13
- 'postgres' ,
14
+ {
15
+ name : 'pg' ,
16
+ Pool : PgPool ,
17
+ } ,
18
+ {
19
+ name : 'postgres-bridge' ,
20
+ Pool : PostgresBridge ,
21
+ } ,
14
22
] ;
15
23
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 ( {
31
30
user : 'postgres' ,
32
31
} ) ;
33
32
@@ -42,8 +41,8 @@ for (const client of clients) {
42
41
t . is ( spy . firstCall . args [ 0 ] , connection ) ;
43
42
} ) ;
44
43
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 ( {
47
46
user : 'postgres' ,
48
47
} ) ;
49
48
@@ -58,7 +57,7 @@ for (const client of clients) {
58
57
DECLARE
59
58
a INT:= 10;
60
59
BEGIN
61
- RAISE NOTICE 'value of a: %', a;
60
+ RAISE NOTICE 'value of a: %', a;
62
61
END;
63
62
$$
64
63
LANGUAGE plpgsql;
@@ -81,8 +80,8 @@ for (const client of clients) {
81
80
} ) ;
82
81
} ) ;
83
82
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 ( {
86
85
user : 'postgres' ,
87
86
} ) ;
88
87
@@ -97,8 +96,8 @@ for (const client of clients) {
97
96
await connection2 . end ( ) ;
98
97
} ) ;
99
98
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 ( {
102
101
user : 'postgres' ,
103
102
} ) ;
104
103
@@ -111,8 +110,8 @@ for (const client of clients) {
111
110
t . is ( pool . idleCount , 1 ) ;
112
111
} ) ;
113
112
114
- test ( client + ': query method' , async ( t ) => {
115
- const pool = createPool ( client , {
113
+ test ( clientName + ': query method' , async ( t ) => {
114
+ const pool = new Pool ( {
116
115
user : 'postgres' ,
117
116
} ) ;
118
117
@@ -133,8 +132,8 @@ for (const client of clients) {
133
132
} ) ;
134
133
} ) ;
135
134
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 ( {
138
137
user : 'postgres' ,
139
138
} ) ;
140
139
@@ -157,8 +156,8 @@ for (const client of clients) {
157
156
} ) ;
158
157
} ) ;
159
158
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 ( {
162
161
user : 'postgres' ,
163
162
} ) ;
164
163
0 commit comments