From df4892fb2b7abdbdc59ae7f9a7048b3fee1f9a07 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 3 Sep 2015 18:31:54 -0400 Subject: starting to write apis --- lib/db/index.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'lib/db/index.js') diff --git a/lib/db/index.js b/lib/db/index.js index f539b90..3761417 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -35,7 +35,7 @@ var Message = db.Message = bookshelf.Model.extend({ hasTimestamps: false, }) -/* PICTURES */ +/* USERS */ db.createUser = function(data){ return new db.User(data).save() @@ -53,8 +53,27 @@ db.getUserByUsername = function(username) { var model = new User({'username': username}) return model.fetch() } -db.getThreads = function () { - return User.query(function(qb){ - qb.orderBy("id", "desc") + +/* THREADS */ + +db.getLatestThreads = function () { + return Thread.query(function(qb){ + qb.orderBy("id", "desc").limit(50) }).fetchAll() -} \ No newline at end of file +} + +/* FILES */ +db.getFilesForThread = function (id){ + return File.query("where", "thread", "=", id).fetchAll() +} +db.getFileCounts = function(ids){ + return knex.column('thread', 'count(*)').select().from('comments').where('thread', 'in', ids).groupBy('thread') +} + +/* COMMENTS */ +db.getCommentsForThread = function (id){ + return Comment.query("where", "thread", "=", id).fetchAll() +} +db.getCommentCounts = function(){ + return knex.column('thread', 'count(*)').select().from('files').where('thread', 'in', ids).groupBy('thread') +} -- cgit v1.2.3-70-g09d2