summaryrefslogtreecommitdiff
path: root/lib/db/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/db/index.js')
-rw-r--r--lib/db/index.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/db/index.js b/lib/db/index.js
index 33beae9..b7b1b06 100644
--- a/lib/db/index.js
+++ b/lib/db/index.js
@@ -11,3 +11,19 @@ var Image = db.Image = bookshelf.Model.extend({
tableName: 'images',
hasTimestamps: false,
})
+
+db.getImage = function(id) {
+ var model = new Image({'id': id})
+ return model.fetch()
+}
+db.getLatest = function () {
+ return Image.query(function(qb){
+ qb.orderBy("id", "desc").limit(1)
+ }).fetch()
+}
+db.getRandom = function () {
+ return Image.query(function(qb){
+ qb.orderBy(knex.raw('RANDOM()')).limit(1)
+ }).fetch()
+}
+