diff options
Diffstat (limited to 'bucky/db')
| -rw-r--r-- | bucky/db/index.js | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js index f454c92..312ca13 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -55,8 +55,13 @@ db.createUser = function(data){ } db.getUsers = function () { return User.query(function(qb){ - qb.orderBy("id", "desc") - }).fetchAll() + qb.orderBy("username", "asc") + }).fetchAll({ + columns: [ + "id", "username", "realname", "firstseen", "lastseen", + "location", "website", "avatar", + ] + }) } db.getUser = function(id) { var model = new User({'id': id}) @@ -143,6 +148,15 @@ db.getThreadUsers = function(thread_id){ db.getUserThreadIds = function(user_id){ return ThreadUser.query("where", "user_id", "=", user_id).fetch() } +db.getUserThreadCounts = function(ids){ + return knex.column('username').count('* as count').select().from('threads').groupBy('username') +} +db.getUserCommentCounts = function(ids){ + return knex.column('username').count('* as count').select().from('comments').groupBy('username') +} +db.getUserFileCounts = function(ids){ + return knex.column('username').sum('size as size').count('* as count').select().from('files').groupBy('username') +} /* FILES */ @@ -281,8 +295,24 @@ db.getKeyword = function (keyword) { return Keyword.query("where", "keyword", "=", keyword).fetch() } db.getThreadGroups = function (keyword) { - return knex.column('keyword').sum('viewed').as('viewed').count('*').as('count').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword') + return ( + knex.column('keyword') + .sum('viewed').as('viewed') + .count('*').as('count') + .select().from('threads').groupBy('keyword') + ) +} +db.getLatestKeywordThreads = function (keyword) { + var ids = knex('threads').max('id').groupBy('keyword') + return ( + knex.select('id', 'keyword', 'title', 'lastmodified', 'privacy').from('threads').where('id', 'in', ids) + ) } + // .column('id') + // .column('title') + // .column('lastmodified') + // .column('privacy') + db.createKeyword = function(data){ return new db.Keyword(data).save() } |
