v1.3.0: update for sqlite3@4.x

This commit is contained in:
AJ ONeal 2019-04-04 02:00:13 -06:00
parent e4b47e230b
commit b44e1fd5c6
3 changed files with 23 additions and 8 deletions

View File

@ -1,4 +1,6 @@
'use strict'; 'use strict';
/*global Promise*/
var PromiseA = Promise;
function lowerFirst(str) { function lowerFirst(str) {
return str.charAt(0).toLowerCase() + str.substr(1); return str.charAt(0).toLowerCase() + str.substr(1);
@ -45,7 +47,6 @@ var searchConditions = {
function wrap(db, dir, dbsMap) { function wrap(db, dir, dbsMap) {
// TODO if I put a failure right here, // TODO if I put a failure right here,
// why doesn't the unhandled promise rejection fire? // why doesn't the unhandled promise rejection fire?
var PromiseA = require('bluebird');
var promises = []; var promises = [];
var earr = []; var earr = [];
var debug = false; var debug = false;
@ -493,7 +494,13 @@ function wrap(db, dir, dbsMap) {
DB.save = function (data, oldId) { DB.save = function (data, oldId) {
if (!data[idnameCased] && !oldId) { if (!data[idnameCased] && !oldId) {
// NOTE saving the id both in the object and the id for now // 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*/) { return DB.create(data[idnameCased], data).then(function (/*stats*/) {
//data._rowid = stats.id; //data._rowid = stats.id;
return data; 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) { if (!db.__masterquest_init) {
db.__masterquest_init = true; db.__masterquest_init = true;
db = PromiseA.promisifyAll(db); Object.keys(db).forEach(promisify);
['run', 'all'].forEach(promisify);
db.__masterquest_init = true; db.__masterquest_init = true;
db.escape = function (str) { db.escape = function (str) {
// TODO? literals for true,false,null // TODO? literals for true,false,null

5
package-lock.json generated Normal file
View File

@ -0,0 +1,5 @@
{
"name": "masterquest-sqlite3",
"version": "1.3.0",
"lockfileVersion": 1
}

View File

@ -1,6 +1,6 @@
{ {
"name": "masterquest-sqlite3", "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.", "description": "A NoSQL / SQLite3 Hybrid. All your indices are belong to us. Master Quest.",
"main": "lib/dbwrap", "main": "lib/dbwrap",
"scripts": { "scripts": {
@ -13,8 +13,5 @@
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
"license": "(MIT OR Apache-2.0)", "license": "(MIT OR Apache-2.0)",
"homepage": "https://git.coolaj86.com:coolaj86/masterquest-sqlite3.js", "homepage": "https://git.coolaj86.com:coolaj86/masterquest-sqlite3.js",
"dependencies": { "dependencies": {}
"bluebird": "^3.5.1",
"uuid": "^3.2.1"
}
} }