summaryrefslogtreecommitdiff
path: root/lib/db/index.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-03 18:31:54 -0400
committerJules Laplace <jules@okfoc.us>2015-09-03 18:31:54 -0400
commitdf4892fb2b7abdbdc59ae7f9a7048b3fee1f9a07 (patch)
tree02e61e3e40caa79de43e4d19ecf25c0c1c7fb304 /lib/db/index.js
parentc4f8d3508367de71f708825ccba48096f3490f1f (diff)
starting to write apis
Diffstat (limited to 'lib/db/index.js')
-rw-r--r--lib/db/index.js29
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')
+}