Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.each(suffixMap, (condition, key) => {
if (_.endsWith(arg.name.value, key) && (!found)) {
const columnName = _.head(_.split(arg.name.value, key));
switch (key) {
case '_IsNull':
if (arg.value.value) {
query.whereNull(columnName);
} else {
query.whereNotNull(columnName);
}
break;
case '_In':
query.whereIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_NotIn':
query.whereNotIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_LikeNoCase':
query.whereRaw(condition, [columnName,
isVarDef ? knex.raw(varValue) : values.toLowerCase()
]);
break;
case '_Like':
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
default:
// console.log('columnName, values :: ', columnName, values);
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
if (_.endsWith(arg.name.value, key) && (!found)) {
const columnName = _.head(_.split(arg.name.value, key));
switch (key) {
case '_IsNull':
if (arg.value.value) {
query.whereNull(columnName);
} else {
query.whereNotNull(columnName);
}
break;
case '_In':
query.whereIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_NotIn':
query.whereNotIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_LikeNoCase':
query.whereRaw(condition, [columnName,
isVarDef ? knex.raw(varValue) : values.toLowerCase()
]);
break;
case '_Like':
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
default:
// console.log('columnName, values :: ', columnName, values);
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
}
found = true;
query.whereNotNull(columnName);
}
break;
case '_In':
query.whereIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_NotIn':
query.whereNotIn(columnName, isVarDef ? knex.raw(varValue) : values);
break;
case '_LikeNoCase':
query.whereRaw(condition, [columnName,
isVarDef ? knex.raw(varValue) : values.toLowerCase()
]);
break;
case '_Like':
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
default:
// console.log('columnName, values :: ', columnName, values);
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
}
found = true;
return false;
}
});
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
default:
// console.log('columnName, values :: ', columnName, values);
query.whereRaw(condition, [columnName, isVarDef ? knex.raw(varValue) : values]);
break;
}
found = true;
return false;
}
});
// Its now, safe to assume that this is equals operator..
if (!found) {
query.whereRaw('?? = ?', [arg.name.value, isVarDef ? knex.raw(varValue) : values]);
found = true;
}
return found;
}
let [latitude, longitude] = value.center
// Uses indexes on `latitudeColumn` / `longitudeColumn` if available
query = query
.whereBetween(latitudeColumn, [
latitude - (radius / unitsPerDegree),
latitude + (radius / unitsPerDegree)
])
.whereBetween(longitudeColumn, [
longitude - (radius / (unitsPerDegree * Math.cos(latitude * (Math.PI / 180)))),
longitude + (radius / (unitsPerDegree * Math.cos(latitude * (Math.PI / 180))))
])
if (value.calculateDistance) {
let distanceColumn = (typeof value.calculateDistance === 'string') ? value.calculateDistance : 'distance'
query = query.select(knex.raw(`
${unitsPerDegree} * DEGREES(ACOS(
COS(RADIANS(?)) * COS(RADIANS(${latitudeColumn})) *
COS(RADIANS(${longitudeColumn}) - RADIANS(?)) +
SIN(RADIANS(?)) * SIN(RADIANS(${latitudeColumn}))
)) AS ${distanceColumn}`, [latitude, longitude, latitude]))
}
return query
}
}