initialize db only once

This commit is contained in:
AJ ONeal 2017-05-29 19:38:04 -06:00
parent c825e7af06
commit c753630a29
1 changed files with 26 additions and 24 deletions

View File

@ -12,15 +12,6 @@ function wrap(db, dir, dbsMap) {
dbsMap = {};
}
db.escape = function (str) {
// TODO? literals for true,false,null
// error on undefined?
if (undefined === str) {
str = '';
}
return String(str).replace(/'/g, "''");
};
function lowerFirst(str) {
return str.charAt(0).toLowerCase() + str.slice(1);
}
@ -157,19 +148,6 @@ function wrap(db, dir, dbsMap) {
dir.indices.forEach(normalizeColumn);
DB._indices = dir.indices;
db = PromiseA.promisifyAll(db);
if (dir && dir.verbose || db.verbose) {
console.log('Getting Verbose up in here');
db.on('trace', function (str) {
console.log('SQL:', str);
});
db.on('profile', function (sql, ms) {
console.log('Profile:', ms);
});
}
function simpleParse(row) {
if (!row) {
return null;
@ -581,6 +559,32 @@ function wrap(db, dir, dbsMap) {
});
}
if (!db.__masterquest_init) {
db.__masterquest_init = true;
db = PromiseA.promisifyAll(db);
db.__masterquest_init = true;
db.escape = function (str) {
// TODO? literals for true,false,null
// error on undefined?
if (undefined === str) {
str = '';
}
return String(str).replace(/'/g, "''");
};
if (dir && dir.verbose || db.verbose) {
console.log('Getting Verbose up in here');
db.on('trace', function (str) {
console.log('SQL:', str);
});
db.on('profile', function (sql, ms) {
console.log('Profile:', ms);
});
}
}
dbsMap.sql = db;
dir.forEach(function (dir) {
// TODO if directive is the same as existing dbsMap, skip it
promises.push(createTable(dir).then(function (dbw) {
@ -591,8 +595,6 @@ function wrap(db, dir, dbsMap) {
}));
});
dbsMap.sql = db;
return PromiseA.all(promises).then(function (/*dbs*/) {
return dbsMap;
});