diff options
Diffstat (limited to 'bucky/db/index.js')
| -rw-r--r-- | bucky/db/index.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js index 935219f..a147cd8 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -93,6 +93,16 @@ db.getThreadsForKeyword = function (keyword) { qb.where("keyword", "=", keyword).orderBy("id", "desc") }).fetchAll() } +db.getThreadsForUser = function (username, limit, offset) { + return Thread.query(function(qb){ + qb.where("username", "=", username).orderBy("id", "desc").limit(limit || 40).offset(offset || 0) + }).fetchAll() +} +db.getTopThreadsForUser = function (username, limit, offset) { + return Thread.query(function(qb){ + qb.where("username", "=", username).orderBy("viewed", "desc").limit(limit || 40).offset(offset || 0) + }).fetchAll() +} db.getThread = function (id) { return Thread.query("where", "id", "=", id).fetch() } @@ -138,6 +148,14 @@ db.getFileById = function(id){ db.getFilesForThread = function (id){ return File.query("where", "thread", "=", id).fetchAll() } +db.getFilesForUser = function (username, limit, offset){ + return File.query(function(qb){ + qb.where("username", "=", username) + .orderBy('id', 'desc') + .limit(parseInt(limit) || 20) + .offset(parseInt(offset) || 0) + }).fetchAll() +} db.getFileCounts = function(ids){ return knex.column('thread').count('* as count').select().from('files').where('thread', 'in', ids).groupBy('thread') } @@ -225,6 +243,13 @@ db.getCommentById = function(id){ db.getCommentsById = function(ids){ return Comment.where("id", "in", ids).fetchAll() } +db.getCommentsForUser = function (username, limit){ + return Comment.query(function(qb){ + qb.where("username", "=", username) + .orderBy('date', 'desc') + .limit(parseInt(limit) || 20) + }).fetchAll() +} db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } |
