diff options
Diffstat (limited to 'lib/db/index.js')
| -rw-r--r-- | lib/db/index.js | 29 |
1 files changed, 24 insertions, 5 deletions
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') +} |
