From b817d4472ca905a0d380cf686ffa62f62297574a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 24 Sep 2015 12:33:51 -0400 Subject: db calls --- lib/db/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/db/index.js') 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() +} + -- cgit v1.2.3-70-g09d2