summaryrefslogtreecommitdiff
path: root/lib/db/index.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-07 14:51:20 -0400
committerJules Laplace <jules@okfoc.us>2015-09-07 14:51:20 -0400
commit9957952d2761b1d2b216a9310339e28f25df9f6c (patch)
tree5195075b01434f327b73162eee0fa22825e506fd /lib/db/index.js
parent43265c66f757222bbe8fefb670300c0a3d3b51bf (diff)
mailbox api
Diffstat (limited to 'lib/db/index.js')
-rw-r--r--lib/db/index.js28
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){