From b2d2bc1c592f5263ed30c26b6a8ea5f48e230e90 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 4 Sep 2015 23:24:31 -0400 Subject: db calls --- lib/db/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/db/index.js') diff --git a/lib/db/index.js b/lib/db/index.js index 3761417..8e72d34 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -67,13 +67,16 @@ 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') + return knex.column('thread').count('* as count').select().from('files').where('thread', 'in', ids).groupBy('thread') +} +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){ return Comment.query("where", "thread", "=", id).fetchAll() } -db.getCommentCounts = function(){ - return knex.column('thread', 'count(*)').select().from('files').where('thread', 'in', ids).groupBy('thread') +db.getCommentCounts = function(ids){ + return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } -- cgit v1.2.3-70-g09d2