diff --git a/lib/dbwrap.js b/lib/dbwrap.js index a594867..5cecf42 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -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; });