From 23c3faf43921d8fa7ce2e298da62b794e39f8fa4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 3 Mar 2016 20:22:16 -0500 Subject: [PATCH] allow shared dbsMap, always set created_at and updated_at --- lib/dbwrap.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index 0ab2959..ce70d8a 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -1,14 +1,17 @@ 'use strict'; -function wrap(db, dir) { +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 dbsMap = {}; var debug = false; + if (!dbsMap) { + dbsMap = {}; + } + db.escape = function (str) { return (str||'').toString().replace(/'/g, "''"); }; @@ -324,6 +327,9 @@ function wrap(db, dir) { return PromiseA.reject(new Error("no id supplied")); } + obj.created_at = Date.now(); + obj.updated_at = Date.now(); + return new PromiseA(function (resolve, reject) { var json = JSON.stringify(obj); var data = JSON.parse(json); @@ -449,6 +455,7 @@ function wrap(db, dir) { //var vals = []; // removes known fields from data + data.updated_at = Date.now(); var sql = strainUpdate(id, data/*, vals*/, sqlTpl); //console.log('[debug] DB.set() sql:', sql); @@ -544,6 +551,7 @@ function wrap(db, dir) { } dir.forEach(function (dir) { + // TODO if directive is the same as existing dbsMap, skip it promises.push(createTable(dir).then(function (dbw) { dbsMap[dir.modelname] = dbw;