Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(rows) => // write to database, all valid rows
r.expr(rows).do((row_data) =>
row_data.forEach((info) =>
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),
{ returnChanges: 'always' }))
// Pretend like we deleted rows that didn't exist
r.branch(old_row.eq(null),
group,
old_row.merge(literal_group)))
.run(conn).then((res) => {
if (res.errors) {
throw new Error(`Failed to update group: ${res.first_error}`);
}
});
}));
} else {
// Replace and remove groups
const groups_obj = { };
schema.groups.forEach((g) => { groups_obj[g.id] = g; });
return Promise.all([
r.expr(groups_obj).do((groups) =>
r.db(internal_db).table('groups')
.replace((old_row) =>
r.branch(groups.hasFields(old_row('id')),
old_row,
null))
).run(conn).then((res) => {
if (res.errors) {
throw new Error(`Failed to write groups: ${res.first_error}`);
}
}),
r.db(internal_db).table('groups')
.insert(schema.groups, { conflict: 'replace' })
.run(conn).then((res) => {
if (res.errors) {
throw new Error(`Failed to write groups: ${res.first_error}`);
}
(rows) => // write to database, all valid rows
r.expr(rows)
.forEach((new_row) =>
r.branch(new_row.hasFields('id'),
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(
old_row.eq(null),
r.branch(
// Error if we were expecting the row to exist
new_row.hasFields(hz_v),
r.error(writes.invalidated_msg),
// Otherwise, insert the row
writes.apply_version(new_row, 0)
),
r.branch(
// The row may have changed from the expected version
r.and(new_row.hasFields(hz_v),
function deleteTypesData(conn, commands) {
const names = commands.map((command) => command.type.name);
return RethinkDB.expr(names).forEach((name) => (
RethinkDB.tableDrop(name)
)).run(conn);
}
auth_key (provider, info) {
if (info === null || Array.isArray(info) || typeof info !== 'object') {
return [ provider, info ]
} else {
return [ provider, r.expr(info).toJSON() ]
}
}
function query(row, options = {}) {
const {
apply = query => query,
} = parseOptions(options);
let query = left.table.query();
query = query.getAll(row(right.field), { index: left.field });
query = apply(query);
return r.branch(
row(right.field),
query,
r.expr([]),
);
}
} ).filter( ( doc : any ) => {
if ( included.length > 0 && excluded.length > 0 ) {
return doc( "collections" ).setIntersection( r.expr( included ) ).isEmpty().not().and(
doc( "collections" ).setIntersection( r.expr( excluded ) ).isEmpty()
);
} else if ( excluded.length > 0 ) {
return doc( "collections" ).setIntersection( r.expr( excluded ) ).isEmpty();
} else if ( included.length > 0 ) {
return doc( "collections" ).setIntersection( r.expr( included ) ).isEmpty().not();
}
} );
}
value = parseInt(value, 10);
}
if (operator === '==') {
clause = clause.eq(value);
} else if (operator === '!=') {
clause = clause.ne(value);
} else if (operator === '>') {
clause = clause.gt(value);
} else if (operator === '<') {
clause = clause.lt(value);
} else if (operator === '>=') {
clause = clause.ge(value);
} else if (operator === '<=') {
clause = clause.le(value);
} else if (operator === 'in') {
clause = r.expr(value).contains(clause);
} else if (operator === 'is null') {
clause = clause.eq(null);
}
rql = rql.filter(clause);
}
if (options.sort) {
if (options.direction === 'desc') {
rql2 = rql.orderBy(r.desc(options.sort));
} else {
rql2 = rql.orderBy(options.sort);
}
}
if (!rql2) {
rql2 = rql;
}
return store.utils.Promise.all([