Skip to content

Commit

Permalink
fix: connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Elin Angelow committed Jun 18, 2024
1 parent 3f4ecc3 commit a179beb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@ const SqlWe = (() => (class Sql extends WError {}))();

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

const conn = (() => {
let connection;
const connectionPool = (log) => {
let pool;
return async(config) => {
if (connection === undefined) {
connection = new Pool(config);
return connection;
if (pool === undefined) {
pool = new Pool(config);
pool.on('error', (e) => log('error', 'expose.sql.methods', e));
return pool;
}
return connection;
return pool;
};
})();
};


module.exports = async(config) => {
module.exports = async(
config,
{log = () => {}}
) => {
const {link: {gluePrefix = '.', schemas: sc} = {}} = config;
const schemas = sc instanceof Array ? sc : [sc];
const link = await conn(config.connection);
const link = await connectionPool(log)(
config.connection,
{log}
);
const txMap = new Map();
let txId = 0;

Expand Down

0 comments on commit a179beb

Please sign in to comment.