Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} 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([
// filtered, skipped, ordered and limited data
connection.run(rql2.skip(Table.TABLE_PAGE_SIZE * (parseInt(options.page, 10) - 1)).limit(Table.TABLE_PAGE_SIZE).coerceTo('ARRAY')),
// count query does not need the skip, orderBy, or limit
connection.run(rql.count())
]).then(results => {
return {
data: results[0],
count: results[1]
if (start) {
tableData = yield r.db(db).table(table).between(start, r.maxval, {
leftBound: "open",
index: index
})
.orderBy({
index: index
}).limit(5).run(conn);
} else if (end) {
// TODO: This doesn't work, as it start over from "zero" position
tableData = yield r.db(db).table(table).between(r.minval, end, {
rightBound: "open",
index: index
})
.orderBy({
index: r.desc(index)
}).limit(5).run(conn);
} else {
tableData = yield r.db(db).table(table).orderBy({
index: index || 'id'
}).limit(5).run(conn);
}
resolve(tableData);
}).catch(function(err) {
reject(err);
const config = require('../config.gpindex.json')['gpindex_db']
const event = new EventEmitter();
const segment = new Segment()
var db_conn
var queue = {
public: [],
private: {},
private_update: {}
};
var lock = {}
const sortFunc = {
count_asc: 'member_count',
count_desc: r.desc('member_count'),
id_asc: 'id',
id_desc: r.desc('id'),
title_asc: 'title',
title_desc: r.desc('title')
}
function truncateSearch(term) {
return term.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&')
}
// Flag User
async function setUserFlag(uid, flag, value) {
if (!db_conn) throw new Error('databaseNotConnected');
let user = await r.table('userdata').get(parseInt(uid)).run(db_conn)
let updation = {}
if (Array.isArray(flag) && Array.isArray(value)) {
var db_conn
var queue = {
public: [],
private: {},
private_update: {}
};
var lock = {}
const sortFunc = {
count_asc: 'member_count',
count_desc: r.desc('member_count'),
id_asc: 'id',
id_desc: r.desc('id'),
title_asc: 'title',
title_desc: r.desc('title')
}
function truncateSearch(term) {
return term.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&')
}
// Flag User
async function setUserFlag(uid, flag, value) {
if (!db_conn) throw new Error('databaseNotConnected');
let user = await r.table('userdata').get(parseInt(uid)).run(db_conn)
let updation = {}
if (Array.isArray(flag) && Array.isArray(value)) {
for (let i of flag) {
updation[i] = value[flag.indexOf(i)]
}
} else {
countBookmarks((bookmarkCount) => {
bkmrkd.table('bookmarks').orderBy({
index: rethink.desc('createdOn')
}).skip(25 * (pageNumber - 1)).limit(25).run(connection, (err, cursor) => {
if (err) {
return res.render('500', {
message: 'There\'s been an error getting the initial list of bookmarks.'
})
}
cursor.toArray((err, result) => {
if (err) {
console.error('Error getting the initial list of bookmarks: ', err)
return res.render('500', {
message: 'There\'s been an error getting the initial list of bookmarks.'
})
}
const playlist = await this.server.database.tables.playlists.findOne( query => {
return query.orderBy( { index: r.desc( 'createdAt' ) } ).filter( { device: device } ).limit( 1 );
} );
query = r.table(Model.tableName);
if (!utils.isEmpty(predicate.where)) {
query = query.filter(predicate.where);
}
if (predicate.orderBy) {
if (utils.isString(predicate.orderBy)) {
predicate.orderBy = [
[predicate.orderBy, 'asc']
];
}
for (var i = 0; i < predicate.orderBy.length; i++) {
if (utils.isString(predicate.orderBy[i])) {
predicate.orderBy[i] = [predicate.orderBy[i], 'asc'];
}
query = utils.uppercase(predicate.orderBy[i][1]) === 'DESC' ? query.orderBy(r.desc(predicate.orderBy[i][0])) : query.orderBy(predicate.orderBy[i][0]);
}
}
if (predicate.limit) {
query = query.limit(parseInt(predicate.limit, 10));
}
if (predicate.skip) {
query = query.skip(parseInt(predicate.skip, 10));
}
if (predicate.groupBy) {
query = query.groupBy(predicate.groupBy, r.avg(predicate.avg));
} else {
query = query.avg(predicate.avg);
}
async.waterfall([
p = new Promise(function(resolve, reject) {
r.table('order').getAll(args.restaurantID, {
index: 'restaurantID'
}).orderBy(r.desc('date')).run(rootValue.conn, (err, res) => {
if (err) reject(err);
res.toArray((err, res) => {
if (err) reject(err);
resolve(res);
});
});
});
}
documents: [],
noDoc: true,
primaryKey: primaryKey,
indexes: indexes,
more_data: "0",
count: skip
})
}
else {
var errorFound = false;
if (indexes[order] != null) {
if (ascDescValue === 'asc') {
query = query.orderBy({index: order});
}
else {
query = query.orderBy({index: r.desc(order)});
}
}
else {
if (count === maxCount) {
errorFound = true;
res.json({
error: {
message: "The table has more than "+(maxCount-1)+" elements and no index was found for "+order+"."
}
})
}
else if (ascDescValue === 'asc') {
query = query.orderBy(order);
}
else {
query = query.orderBy(r.desc(order));