diff options
Diffstat (limited to 'lib/db/index.js')
| -rw-r--r-- | lib/db/index.js | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/db/index.js b/lib/db/index.js index 2e63f74..1c7cc15 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -13,7 +13,7 @@ var File = db.File = bookshelf.Model.extend({ hasTimestamps: true, }) var Job = db.Job = bookshelf.Model.extend({ - tableName: 'job', + tableName: 'jobs', hasTimestamps: true, }) var Task = db.Task = bookshelf.Model.extend({ @@ -37,12 +37,19 @@ db.crud = function(model) { qb.orderBy("id", "desc") if (limit) qb.limit( limit ) if (offset) qb.offset( offset ) + // console.log(qb) return qb }).fetchAll() }, show: (id) => { return new model({'id': id}).fetch() }, + show_ids: (ids) => { + return model.query( (qb) => { + qb.whereIn('id', ids) + return qb + }).fetchAll() + }, create: (data) => { return new model(data).save() }, @@ -54,3 +61,16 @@ db.crud = function(model) { }, } } + +function memoize (f) { + const o = {} + return (model) => { + console.log(model) + t = model.toString() + if (o[t]) { + return o[t] + } + o[t] = f(model) + return o[t] + } +}
\ No newline at end of file |
