diff --git a/lib/dbwrap.js b/lib/dbwrap.js index 5175ef9..6787075 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -1,4 +1,6 @@ 'use strict'; +/*global Promise*/ +var PromiseA = Promise; function lowerFirst(str) { return str.charAt(0).toLowerCase() + str.substr(1); @@ -45,7 +47,6 @@ var searchConditions = { function wrap(db, dir, dbsMap) { // TODO if I put a failure right here, // why doesn't the unhandled promise rejection fire? - var PromiseA = require('bluebird'); var promises = []; var earr = []; var debug = false; @@ -493,7 +494,13 @@ function wrap(db, dir, dbsMap) { DB.save = function (data, oldId) { if (!data[idnameCased] && !oldId) { // NOTE saving the id both in the object and the id for now - data[idnameCased] = require('uuid').v4(); + data[idnameCased] = require('crypto').randomBytes(16).toString('hex').split(''); + data[idnameCased].splice(8, 0, '-'); + data[idnameCased].splice(8 + 1 + 4, 0, '-'); + data[idnameCased].splice(8 + 1 + 4 + 1 + 4, 0, '-'); + data[idnameCased].splice(8 + 1 + 4 + 1 + 4 + 1 + 4, 0, '-'); + data[idnameCased][14] = 4; // TODO look at the mock uuid in the Go code I wrote + data[idnameCased] = data[idnameCased].join(''); return DB.create(data[idnameCased], data).then(function (/*stats*/) { //data._rowid = stats.id; return data; @@ -676,9 +683,15 @@ function wrap(db, dir, dbsMap) { }); } + function promisify(key) { + console.log('db[key]', key); + if ('function' !== typeof db[key] || /Async$/.test(key) || db[key + 'Async']) { return; } + db[key + 'Async'] = require('util').promisify(db[key]); + } if (!db.__masterquest_init) { db.__masterquest_init = true; - db = PromiseA.promisifyAll(db); + Object.keys(db).forEach(promisify); + ['run', 'all'].forEach(promisify); db.__masterquest_init = true; db.escape = function (str) { // TODO? literals for true,false,null diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a3315d2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "masterquest-sqlite3", + "version": "1.3.0", + "lockfileVersion": 1 +} diff --git a/package.json b/package.json index 188df05..9f51864 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "masterquest-sqlite3", - "version": "1.2.1", + "version": "1.3.0", "description": "A NoSQL / SQLite3 Hybrid. All your indices are belong to us. Master Quest.", "main": "lib/dbwrap", "scripts": { @@ -13,8 +13,5 @@ "author": "AJ ONeal (https://coolaj86.com/)", "license": "(MIT OR Apache-2.0)", "homepage": "https://git.coolaj86.com:coolaj86/masterquest-sqlite3.js", - "dependencies": { - "bluebird": "^3.5.1", - "uuid": "^3.2.1" - } + "dependencies": {} }