Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const primaryKey = tableOptions.primary || 'id';
const existingConfig = existing[name];
let drop = false;
if (existingConfig &&
existingConfig.primary_key !== primaryKey) {
drop = RethinkDB.db(this.name).tableDrop(name);
}
// Create new table
if (!existingConfig ||
drop) {
const create = RethinkDB.db(this.name).tableCreate(name, { primaryKey });
const change = (drop ? RethinkDB.and(drop, create) : create);
await change.run(this._connection);
}
else {
// Reuse existing table
if (tableOptions.purge !== false) { // Defaults to true
await this.tables[name].empty();
}
if (tableOptions.secondary !== false) { // false means leave as-is (vs null or empty array which drops existing)
for (let j = 0; j < existingConfig.indexes.length; ++j) {
const index = existingConfig.indexes[j];
await RethinkDB.db(this.name).table(name).indexDrop(index).run(this._connection);
}
}
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise we can safely update the row and increment the version
writes.apply_version(old_row.merge(new_row), old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
collection.table.get(info('id')).replace((row) =>
r.branch(// The row may have been deleted between the get and now
row.eq(null),
null,
// The row may have been changed between the get and now
r.and(info.hasFields(hz_v),
row(hz_v).default(-1).ne(info(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise, we can safely remove the row
null),
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise we can safely update the row and increment the version
writes.apply_version(old_row.merge(new_row), old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
module.exports.fetchByUserIdClientId = function(userId, clientId, cb) {
var where = RethinkDb.and(
RethinkDb.row('userId').eq(userId),
RethinkDb.row('clientId').eq(clientId),
RethinkDb.row('ttl').gt(new Date().getTime())
);
connection.acquire(function(err, conn) {
if (err) cb(err);
else {
RethinkDb.table(TABLE).filter(where).orderBy(RethinkDb.desc('ttl')).limit(1).run(conn, function(err, cursor) {
if (err) cb(err);
else cursor.next(cb);
});
}
});
};
.then(party => {
if (!party) {
return undefined;
}
var accountsPromise;
if(_.isEmpty(party.accounts)) {
accountsPromise = transaction.findExact(
r.and(r.row('Updates').nth(0)('UpdateType').eq(UpdateTypes.REGISTER_ACCOUNT),
r.row.hasFields('creator'),
r.row('creator').eq(id)),
{asArray: true})
.then(txns => _.map(txns, t => ({
id: t.id,
name: t.Updates[0].Name,
description: t.Updates[0].Description,
pending: true
})));
} else {
accountsPromise = Promise.resolve(party.accounts);
}
return accountsPromise.then(accounts => {
party.account = _.first(accounts);
return _.omit(party, 'address', 'accounts');
availableOffers: (participantId, options) =>
_doFetch(
participantId,
r.or(r.row('execution').eq('Any'),
r.row('execution').eq('ExecuteOnce'),
r.and(r.row('execution').eq('ExecuteOncePerParticipant'),
r.row('execution-state')('ParticipantList').contains(participantId).not())),
options),
.then(participant => {
if(participant) {
return participant;
}
return transaction.findExact(
r.and(r.row('Updates').nth(0)('UpdateType').eq(UpdateTypes.REGISTER_PARTICIPANT),
r.row('Status').eq(TransactionStatuses.PENDING),
r.row('address').eq(address)),
{asArray: true})
.then(txns => _.map(txns, (t) => ({
id: t.id,
displayName: t.Updates[0].Name,
name: t.Updates[0].Name,
description: t.Updates[0].Description,
pending: true
})))
.then(_.first);
}),
.filter((row) => r.and(row('db').eq(this._db),
row('name').match('^hz_').not()))
.map((row) => ({
.filter(t => r.and(t('Status').eq(TransactionStatuses.PENDING),
t('creator').eq(participantId),
_update(t)('UpdateType').eq(UpdateTypes.EXCHANGE),
_update(t)('OfferIdList').contains(offer('id'))))
.count().gt(0);