Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var secondaryFilters = [];
// filter this first, as it is more specific than assets
if (opts.filter.holdingId) {
secondaryFilters.push(r.or(r.row('input')('id').eq(opts.filter.holdingId),
r.row('output')('id').eq(opts.filter.holdingId)));
} else if (opts.filter.assetId) {
secondaryFilters.push(r.or(r.row('input')('asset').eq(opts.filter.assetId),
r.row('output')('asset').eq(opts.filter.assetId)));
} else if (opts.filter.inputAssetId) {
secondaryFilters.push(r.row('input')('asset').eq(opts.filter.inputAssetId));
} else if (opts.filter.outputAssetId) {
secondaryFilters.push(r.row('output')('asset').eq(opts.filter.outputAssetId));
}
if (secondaryFilters.length > 0) {
query = query.filter(r.and(r.args(secondaryFilters)));
}
if (opts.count) {
return query.count();
}
if (opts.sort) {
query = query.orderBy(opts.sort);
}
if (opts.limit && opts.page && opts.page > 0) {
query = query.skip(opts.limit * opts.page);
}
if (opts.limit) {
query = query.limit(opts.limit);
exports.select = function (criteria, table, options = {}) {
if (criteria === null) {
return table.raw;
}
// Optimize secondary index query
if (Special.isSpecial(criteria) &&
criteria.type === 'by') {
return table.raw.getAll(RethinkDB.args(criteria.value), { index: criteria.flags.index });
}
// Construct query
const base = (table._geo ? Geo.select(criteria, table) : table.raw);
const filter = internals.compile(criteria, null, options);
return (filter ? base.filter(filter) : base);
};
TransactionStatuses.COMMITTED,
TransactionStatuses.FAILED
];
let ands = [
queries.$in('Status', statuses),
_update(r.row)('UpdateType').eq(UpdateTypes.EXCHANGE),
];
if(optionalCreatorId) {
ands.push(r.row('creator').eq(optionalCreatorId));
} else {
ands.push(_update(r.row)('OfferIdList').isEmpty().not());
}
let query = r.and(r.args(ands));
var findOptions = {
page: options.page,
limit: options.limit,
asArray: true,
};
// filter holding first, as it is more specific
if(options.filter.holdingId) {
findOptions.secondaryQuery = r.or(r.row('input')('id').eq(options.filter.holdingId),
r.row('output')('id').eq(options.filter.holdingId),
r.row('id').eq(options.filter.holdingId));
} else if (options.filter.assetId) {
findOptions.secondaryQuery = r.or(r.row('input')('asset').eq(options.filter.assetId),
r.row('output')('asset').eq(options.filter.assetId),
r.row('id').eq(options.filter.assetId));
AUGUST: r.august,
SEPTEMBER: r.september,
OCTOBER: r.october,
NOVEMBER: r.november,
DECEMBER: r.december,
LITERAL: r.literal({}),
GROUP: r([]).group(''),
SUM: r([]).sum(),
AVG: r([]).avg(),
MIN: r([]).min(),
MAX: r([]).max(),
SPLIT: r([]).split(),
UNGROUP: r([]).ungroup(),
RANDOM: r.random(),
CHANGES: r([]).changes(),
ARGS: r.args([]),
BINARY: r.binary(new Buffer(0)),
GEOJSON: r.geojson({}),
TO_GEOJSON: r({}).toGeojson(),
POINT: r.point(0, 0),
LINE: r.line([], []),
POLYGON: r.polygon([], [], []),
DISTANCE: r.distance([], []),
INTERSECTS: r.intersects(),
INCLUDES: r([]).includes([]),
CIRCLE: r.circle([], 0),
GET_INTERSECTING: r([]).getIntersecting([]),
FILL: r.line([], []).fill(),
GET_NEAREST: r([]).getNearest([]),
POLYGON_SUB: r.polygon([], [], []).polygonSub([]),
MINVAL: r.minval,
MAXVAL: r.maxval,
async _update(ids, changes, track) {
try {
const batch = Array.isArray(ids);
ids = Id.normalize(ids, { allowArray: true });
const postUnique = await Unique.reserve(this, changes, (batch ? true : ids));
const wrapped = Modifier.wrap(changes, this);
const opts = { returnChanges: !!postUnique };
const query = (batch ? this.raw.getAll(RethinkDB.args(ids)) : this.raw.get(ids));
const result = await this._db._run(query.replace(wrapped, opts), track);
if (postUnique) {
return postUnique(result.changes);
}
}
catch (err) {
throw internals.Table.error(err, track);
}
}
function queryRelation(onePk, otherPk) {
let query = relationTable.query();
if (index) {
if (_.isArray(otherPk)) {
query = query.getAll(r.args(otherPk.map(otherPk => [onePk, otherPk])), { index });
} else {
query = query.getAll([onePk, otherPk], { index });
}
} else {
query = query.getAll(onePk, { index: link1.left.field });
if (_.isArray(otherPk)) {
query = query.filter(row => r.expr(otherPk).contains(row(link2.left.field)));
} else {
query = query.filter({ [link2.left.field]: otherPk });
}
}
return query;
}
function queryRelation(onePk, otherPk) {
let query = relationTable.query();
if (index) {
if (_.isArray(otherPk)) {
query = query.getAll(r.args(otherPk.map(otherPk => [onePk, otherPk])), { index });
} else {
query = query.getAll([onePk, otherPk], { index });
}
} else {
query = query.getAll(onePk, { index: link1.left.field });
if (_.isArray(otherPk)) {
query = query.filter(row => r.expr(otherPk).contains(row(link2.left.field)));
} else {
query = query.filter({ [link2.left.field]: otherPk });
}
}
return query;
}
r.connect(self.connection).then(function(conn){
return r.table('data').getAll(r.args(ids), {index: index}).run(conn);
}).then(function(cursor){
cursor.toArray(cb);
const relatedRowsQuery = targetIdsQuery.do(targetIds =>
r.branch(
targetIds.count().gt(0),
link2.right.table.query()
.getAll(r.args(targetIds), { index: link2.right.field }),
r.expr([])
)
);
async get(ids, options = {}) {
const track = { table: this.name, action: 'get', inputs: { ids, options } };
try {
const batch = Array.isArray(ids);
ids = Id.normalize(ids, { allowArray: true });
const query = (batch ? this.raw.getAll(RethinkDB.args(ids)) : this.raw.get(ids));
const items = await this._db._run(this._refine(query, options), track);
return this._read(items);
}
catch (err) {
throw internals.Table.error(err, track);
}
}