Skip to content

Commit a179beb

Browse files
author
Elin Angelow
committedJun 18, 2024
fix: connection
1 parent 3f4ecc3 commit a179beb

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed
 

‎lib/postgres/index.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ const SqlWe = (() => (class Sql extends WError {}))();
66

77
const predefinedSql = require('./sqls/index.js')();
88

9-
const conn = (() => {
10-
let connection;
9+
const connectionPool = (log) => {
10+
let pool;
1111
return async(config) => {
12-
if (connection === undefined) {
13-
connection = new Pool(config);
14-
return connection;
12+
if (pool === undefined) {
13+
pool = new Pool(config);
14+
pool.on('error', (e) => log('error', 'expose.sql.methods', e));
15+
return pool;
1516
}
16-
return connection;
17+
return pool;
1718
};
18-
})();
19+
};
1920

2021

21-
module.exports = async(config) => {
22+
module.exports = async(
23+
config,
24+
{log = () => {}}
25+
) => {
2226
const {link: {gluePrefix = '.', schemas: sc} = {}} = config;
2327
const schemas = sc instanceof Array ? sc : [sc];
24-
const link = await conn(config.connection);
28+
const link = await connectionPool(log)(
29+
config.connection,
30+
{log}
31+
);
2532
const txMap = new Map();
2633
let txId = 0;
2734

0 commit comments

Comments
 (0)
Please sign in to comment.