Make database.initialize async

This commit is contained in:
Girish Ramakrishnan
2021-08-22 17:14:00 -07:00
parent 1052889795
commit b6f2d6d620
3 changed files with 28 additions and 44 deletions

View File

@@ -32,10 +32,8 @@ const gDatabase = {
name: 'box'
};
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
if (gConnectionPool !== null) return callback(null);
async function initialize() {
if (gConnectionPool !== null) return;
if (constants.TEST) {
// see setupTest script how the mysql-server is run
@@ -66,14 +64,12 @@ function initialize(callback) {
connection.query('USE ' + gDatabase.name);
connection.query('SET SESSION sql_mode = \'strict_all_tables\'');
});
callback(null);
}
function uninitialize(callback) {
if (!gConnectionPool) return callback(null);
async function uninitialize() {
if (!gConnectionPool) return;
gConnectionPool.end(callback);
gConnectionPool.end();
gConnectionPool = null;
}