diff options
Diffstat (limited to 'lib/db/index.js')
| -rw-r--r-- | lib/db/index.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/db/index.js b/lib/db/index.js index 1ebae57..ab4cdcf 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -4,6 +4,7 @@ var connection = require("./bookshelf") var bookshelf = connection.bookshelf var knex = connection.knex + /* MODELS */ var User = db.User = bookshelf.Model.extend({ @@ -74,6 +75,7 @@ db.getThread = function (id) { return Thread.query("where", "id", "=", id).fetch() } + /* FILES */ db.getFilesForThread = function (id){ @@ -86,6 +88,7 @@ db.getFileSizes = function(ids){ return knex.column('thread').sum('size as size').select().from('files').where('thread', 'in', ids).groupBy('thread') } + /* COMMENTS */ db.getCommentsForThread = function (id, limit, offset, order){ @@ -109,6 +112,7 @@ db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } + /* KEYWORDS */ db.getKeywords = function (keywords){ @@ -119,8 +123,30 @@ db.getKeyword = function (keyword) { } -/* PRIVATE MESSAGES */ +/* MAILBOXES */ + +db.getMailboxes = function(username){ + return Mailbox.query("where", "owner", "=", username).fetchAll() +} +db.getMailboxCounts = function(boxes){ + return knex.column('mbox').count('* as count').select().from('messages').where('mbox', 'in', boxes).groupBy('mbox') +} + + +/* MESSAGES */ +db.getMessages = function(username, box, limit, offset){ + var mbox = username + "." + box + return Message.query(function(qb){ + qb.column('id', 'mbox', 'unread', 'sender', 'recipient', 'date', 'subject').where("mbox", "=", mbox).orderBy("id", "desc") + if (limit) { + qb.limit(limit) + } + if (offset) { + qb.offset(offset) + } + }).fetchAll() +} db.getMessage = function (id){ var model = new Message({'id': id}) return model.fetch().then(function(message){ |
