diff options
Diffstat (limited to 'bucky/db/index.js')
| -rw-r--r-- | bucky/db/index.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js index c2cf947..8715125 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -51,8 +51,7 @@ db.getUser = function(id) { return model.fetch() } db.getUserByUsername = function(username) { - var model = new User({'username': username}) - return model.fetch() + return new User({'username': username}).fetch() } db.getLastlog = function(limit){ return knex.column('username').column('lastseen').select().from('users').orderBy('lastseen', 'desc').limit(limit || 10) @@ -188,12 +187,18 @@ db.destroyKeyword = function(id){ db.getMailboxes = function(username){ return Mailbox.query("where", "owner", "=", username).fetchAll() } +db.getMailbox = function(mbox){ + return new Mailbox({mbox: mbox}).fetch() +} db.getMailboxCounts = function(boxes){ return knex.column('mbox').count('* as count').select().from('messages').where('mbox', 'in', boxes).groupBy('mbox') } db.createMailbox = function(data){ return new db.Mailbox(data).save() } +db.bumpMailboxCount = function(mbox){ + new db.Mailbox({ mbox: mbox }).fetch() +} /* MESSAGES */ @@ -212,6 +217,7 @@ db.getMessages = function(username, box, limit, offset){ db.getMessage = function (id){ var model = new Message({'id': id}) return model.fetch().then(function(message){ + if (! message) return null message.set("body", message.get("body").toString() ) return message }) |
