mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Remove rutil in favor of the updated rethinkdb driver.
This commit is contained in:
parent
9604f2dde2
commit
4234bb9e34
3 changed files with 8 additions and 34 deletions
|
@ -1,5 +1,6 @@
|
||||||
|
var r = require('rethinkdb')
|
||||||
|
|
||||||
var setup = require('./setup')
|
var setup = require('./setup')
|
||||||
var rutil = require('../util/rutil')
|
|
||||||
var logger = require('../util/logger')
|
var logger = require('../util/logger')
|
||||||
var lifecycle = require('../util/lifecycle')
|
var lifecycle = require('../util/lifecycle')
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ var db = module.exports = Object.create(null)
|
||||||
var log = logger.createLogger('db')
|
var log = logger.createLogger('db')
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
return rutil.connect({
|
return r.connect({
|
||||||
// These environment variables are exposed when we --link to a
|
// These environment variables are exposed when we --link to a
|
||||||
// RethinkDB container.
|
// RethinkDB container.
|
||||||
host: process.env.RETHINKDB_PORT_28015_TCP_ADDR || '127.0.0.1'
|
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
|
// Close connection, we don't really care if it hasn't been created yet or not
|
||||||
db.close = function() {
|
db.close = function() {
|
||||||
return db.connect().then(function(conn) {
|
return db.connect().then(function(conn) {
|
||||||
return rutil.close(conn)
|
return conn.close()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small utility for running queries without having to acquire a connection
|
// Small utility for running queries without having to acquire a connection
|
||||||
db.run = function(q, options) {
|
db.run = function(q, options) {
|
||||||
return db.connect().then(function(conn) {
|
return db.connect().then(function(conn) {
|
||||||
return rutil.run(conn, q, options)
|
return q.run(conn, options)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ var r = require('rethinkdb')
|
||||||
var Promise = require('bluebird')
|
var Promise = require('bluebird')
|
||||||
|
|
||||||
var logger = require('../util/logger')
|
var logger = require('../util/logger')
|
||||||
var rutil = require('../util/rutil')
|
|
||||||
var tables = require('./tables')
|
var tables = require('./tables')
|
||||||
|
|
||||||
module.exports = function(conn) {
|
module.exports = function(conn) {
|
||||||
|
@ -17,7 +16,7 @@ module.exports = function(conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDatabase() {
|
function createDatabase() {
|
||||||
return rutil.run(conn, r.dbCreate(conn.db))
|
return r.dbCreate(conn.db).run(conn)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log.info('Database "%s" created', conn.db)
|
log.info('Database "%s" created', conn.db)
|
||||||
})
|
})
|
||||||
|
@ -31,7 +30,7 @@ module.exports = function(conn) {
|
||||||
var tableOptions = {
|
var tableOptions = {
|
||||||
primaryKey: options.primaryKey
|
primaryKey: options.primaryKey
|
||||||
}
|
}
|
||||||
return rutil.run(conn, r.tableCreate(table, tableOptions))
|
return r.tableCreate(table, tableOptions).run(conn)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log.info('Table "%s" created', table)
|
log.info('Table "%s" created', table)
|
||||||
})
|
})
|
||||||
|
@ -54,7 +53,7 @@ module.exports = function(conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createIndex(table, index, fn) {
|
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() {
|
.then(function() {
|
||||||
log.info('Index "%s"."%s" created', table, index)
|
log.info('Index "%s"."%s" created', table, index)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue