Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, function(err, conn) {
if (err) {
failedAttempts++;
console.log("Attempt: "+failedAttempts)
console.error("Could not open a connection to rethinkdb\n"+err.message);
return setTimeout(init, failedAttempts*5000);
}
// Initialize the table with first the database
r.dbCreate(config.rethinkdb.db).run(conn, function(err, result) {
// If the database already exists, we'll get an error here, but we'll just keep going
r.db(config.rethinkdb.db).tableCreate('benford').run(conn, function(err, result) {
// If the table already exists, we'll get an error here, but we'll just keep going
var seeds = [];
for(var i=1; i<10; i++) {
seeds.push({id: ""+i, value: 0}); // Note: We use the digit value as the primary key and save it as a string
}
r.db(config.rethinkdb.db).table('benford').insert(seeds).run(conn, function(err, result) {
// If the database was already initialized, the inserts will not be executed since RethinkDB
// does not allow redundant primary keys (`id`)
listen();
});
});
});
});
.then(function (conn) {
r.conn = conn;
r.connections.push(conn);
return r.dbCreate(dbConnection.db).run(r.conn)
.catch(function () {})
.then(function () {
r.conn.use(dbConnection.db);
// Create Tables
return r.tableList().run(r.conn)
.then(function (tableList) {
return q()
.then(function() {
if (tableList.indexOf('images') === -1) {
return r.tableCreate('images').run(r.conn);
}
});
});
});
});
r.connect(host, function(err, conn) {
if (err) return error(err);
// create database
r.dbCreate(database).run(conn, function(err) {
if (err) return error(err);
// load the fixtures
async.map(fs.readdirSync(__dirname + '/../fixtures/'), function(file, done) {
var fixture = require(__dirname + '/../fixtures/' + file);
// create table
r.db(database).tableCreate(fixture.table).run(conn, function(err) {
if (err) return done(err);
// create secondary indices
async.map(fixture.secondary_indexes, function(index, loop) {
var q = r.db(database).table(fixture.table);
q.indexCreate.apply(q, index).run(conn, loop);
}, function(err) {
if (err) return done(err);
const initialize_metadata = (db, conn) =>
r.branch(r.dbList().contains(db), null, r.dbCreate(db)).run(conn)
.then(() =>
Promise.all([ 'hz_collections', 'hz_users_auth', 'hz_groups' ].map((table) =>
r.branch(r.db(db).tableList().contains(table),
{ },
r.db(db).tableCreate(table))
.run(conn))))
.then(() =>
r.db(db).table('hz_collections').wait({ timeout: 30 }).run(conn))
.then(() =>
Promise.all([
r.db(db).tableList().contains('users').not().run(conn).then(() =>
create_collection(db, 'users', conn)),
r.db(db).table('hz_collections')
.insert({ id: 'hz_metadata', version: metadata_version })
.run(conn)
])
r.connect(config, (err, conn) => {
r.dbCreate('anchor')
.run(conn, (err, res) => {
conn.close()
next(err, res)
})
})
}
.then(function(dbList) {
if (dbList.indexOf(dbName) === -1)
return r.dbCreate(dbName).run(conn)
})
.then(function() {
.then(dbExists => {
if (dbExists) throw new Error(`"${NAME}" already exists`)
return r.dbCreate(NAME).run(conn)
})
.then(res => {