allow shared dbsMap, always set created_at and updated_at
This commit is contained in:
parent
e726c24a83
commit
23c3faf439
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue