Skip to content

Commit 10f5de1

Browse files
committed
Close client after DB creation.
1 parent 6ceb70a commit 10f5de1

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

js/setup/database.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function logToFile(sql, isData) {
413413
}
414414
}
415415

416-
function createSchema(runSQL = true, logFile = true) {
416+
async function createSchema(runSQL = true, logFile = true) {
417417
let { sql, sqlData } = sqlSchemaWithData();
418418

419419
if (runSQL) {
@@ -422,28 +422,19 @@ function createSchema(runSQL = true, logFile = true) {
422422
dbConfig.idleTimeoutMillis = 30000; // max client idle time before being closed
423423
const pool = new pg.Pool(dbConfig);
424424

425+
// - Create schema and tables
425426
if (logFile) {
426427
logToFile(sql, false);
427428
}
428-
pool.connect(function (err, client, done) {
429-
// - Create schema and tables
430-
client.query(sql, function (err, data) {
431-
if (err) {
432-
done();
433-
throw err;
434-
}
435-
// - Populate tables
436-
if (logFile) {
437-
logToFile(sqlData, true);
438-
}
439-
client.query(sqlData, function (err, data) {
440-
done();
441-
if (err) {
442-
throw err;
443-
}
444-
});
445-
});
446-
});
429+
const client = await pool.connect();
430+
await client.query(sql);
431+
// - Populate tables
432+
if (logFile) {
433+
logToFile(sqlData, true);
434+
}
435+
await client.query(sqlData);
436+
// - close connection
437+
client.release(true);
447438
}
448439
}
449440

0 commit comments

Comments
 (0)