summaryrefslogtreecommitdiff
path: root/bucky/db/index.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-01-25 02:15:48 +0100
committerJules Laplace <julescarbon@gmail.com>2018-01-25 02:15:48 +0100
commitf8055775f3ac74e9e6054aef102673cefcf27986 (patch)
tree6c7c302746db594ff0d61863f533633c7259de33 /bucky/db/index.js
parent3975b8e7e2841298da1ad497ffe29ba004b55ec2 (diff)
more on profile
Diffstat (limited to 'bucky/db/index.js')
-rw-r--r--bucky/db/index.js25
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')
}