1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00

Remove rutil in favor of the updated rethinkdb driver.

This commit is contained in:
Simo Kinnunen 2014-07-22 12:55:33 +09:00
parent 9604f2dde2
commit 4234bb9e34
3 changed files with 8 additions and 34 deletions

View file

@ -1,5 +1,6 @@
var r = require('rethinkdb')
var setup = require('./setup')
var rutil = require('../util/rutil')
var logger = require('../util/logger')
var lifecycle = require('../util/lifecycle')
@ -7,7 +8,7 @@ var db = module.exports = Object.create(null)
var log = logger.createLogger('db')
function connect() {
return rutil.connect({
return r.connect({
// These environment variables are exposed when we --link to a
// RethinkDB container.
host: process.env.RETHINKDB_PORT_28015_TCP_ADDR || '127.0.0.1'
@ -42,14 +43,14 @@ db.connect = (function() {
// Close connection, we don't really care if it hasn't been created yet or not
db.close = function() {
return db.connect().then(function(conn) {
return rutil.close(conn)
return conn.close()
})
}
// Small utility for running queries without having to acquire a connection
db.run = function(q, options) {
return db.connect().then(function(conn) {
return rutil.run(conn, q, options)
return q.run(conn, options)
})
}

View file

@ -2,7 +2,6 @@ var r = require('rethinkdb')
var Promise = require('bluebird')
var logger = require('../util/logger')
var rutil = require('../util/rutil')
var tables = require('./tables')
module.exports = function(conn) {
@ -17,7 +16,7 @@ module.exports = function(conn) {
}
function createDatabase() {
return rutil.run(conn, r.dbCreate(conn.db))
return r.dbCreate(conn.db).run(conn)
.then(function() {
log.info('Database "%s" created', conn.db)
})
@ -31,7 +30,7 @@ module.exports = function(conn) {
var tableOptions = {
primaryKey: options.primaryKey
}
return rutil.run(conn, r.tableCreate(table, tableOptions))
return r.tableCreate(table, tableOptions).run(conn)
.then(function() {
log.info('Table "%s" created', table)
})
@ -54,7 +53,7 @@ module.exports = function(conn) {
}
function createIndex(table, index, fn) {
return rutil.run(conn, r.table(table).indexCreate(index, fn))
return r.table(table).indexCreate(index, fn).run(conn)
.then(function() {
log.info('Index "%s"."%s" created', table, index)
})

View file

@ -1,26 +0,0 @@
var r = require('rethinkdb')
var re = require('rethinkdb/errors')
var Promise = require('bluebird')
module.exports.errors = re
module.exports.connect = function(options) {
var resolver = Promise.defer()
r.connect(options, resolver.callback)
return resolver.promise
}
module.exports.close = function(conn, options) {
var resolver = Promise.defer()
if (!options) {
options = {}
}
conn.close(options, resolver.callback)
return resolver.promise
}
module.exports.run = function(conn, q, options) {
var resolver = Promise.defer()
q.run(conn, options || {}, resolver.callback)
return resolver.promise
}