Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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);
}
});
});
});
});
RethinkDBAdapter.prototype.drop = function drop(collectionName, cb) {
var _this = this;
// Drop the table if it exists
this.connectionRun(r.tableList(), function (err, tableList) {
if (tableList && _.indexOf(tableList, collectionName) !== -1) {
_this.connectionRun(r.tableDrop(collectionName), function (err, result) {
if (err) {
cb(err);
} else if (result.dropped !== 1) {
cb('Failed to drop table: ' + collectionName);
} else {
cb();
}
});
} else {
cb();
}
});
};
const deleteUser = async(ctx, next) => {
await next()
// Get the db connection.
const connection = await db()
// Throw the error if the table does not exist.
var exists = await r.tableList().contains('users').run(connection)
if (exists === false) {
ctx.throw(500, 'users table does not exist')
}
let body = ctx.request.body || {}
// Throw the error if no id.
if (body.id === undefined) {
ctx.throw(400, 'id is required')
}
let objectId = body.id
// Delete a single document by id.
// https://rethinkdb.com/api/javascript/delete/
var result = await r.table('users')
.then(function (conn) {
return r.tableList().run(conn);
})
.then(throwError, expectError.bind(null, 'ReqlDriverError', /DATABASE/i))
static async ensureTable(connection) {
await r.branch(
r.tableList().contains(this.table).not(),
r.tableCreate(this.table),
null
).run(connection);
}
async function main() {
await runMigration([
RethinkDB.do(
RethinkDB.tableList(),
(tables) =>
RethinkDB.branch(
tables.contains('ReindexHook'),
{},
RethinkDB.tableCreate('ReindexHook')
)
),
]);
}
}).then(() => {
return r.tableList().contains('settings').run(conn).then((exists) => {
if (!exists) {
return r.tableCreate('settings').run(conn).then(() => {
return r.table('settings').insert({ name: 'Prompt', value: 'Hello' }).run(conn);
});
} else {
return Promise.resolve();
}
});
});
});
async ensureTable(connection) {
debug(`ensureTable ${connection.db}.${this.tableName}...`);
await r.branch(
r.tableList().contains(this.tableName).not(),
r.tableCreate(this.tableName),
null
).run(connection);
debug(`[done] ensureTable ${connection.db}.${this.tableName}`);
}
.then(function () {
return r.tableList().run(Connection);
})
.then(function (tables) {