@useorbis/db-sdk
Version:
Orbis' Typescript SDK for building open-data experiences.
90 lines (89 loc) • 3.19 kB
JavaScript
/**
*
* AGGREGATE OPERATORS
*
*/
// SUM(DISTINCT? column) AS alias|column
// .select($sum(column, alias, distinct)
const $sum = (column, alias, distinct) => ({
[alias ?? column]: { $sum: { $expr: column, $distinct: distinct } },
});
// COUNT(DISTINCT? column) AS alias|column
// .select($count(column, alias, distinct)
const $count = (column, alias, distinct) => ({
[alias ?? column]: { $count: { $expr: column, $distinct: distinct } },
});
/**
*
* COLUMN OPERATORS
*
*/
// column AS alias
const $as = (column, alias) => ({
[column]: { $as: alias },
});
/**
*
* LOGICAL OPERATORS
*
*/
// condition AND condition AND ...
// .where(
// $and({ column: value }, { column: value })
// )
const $and = (...conditions) => ({
$and: conditions,
});
// condition OR condition OR ..
// .where(
// $or({ column: value }, { column: value })
// )
const $or = (...conditions) => ({
$or: conditions,
});
/**
*
* COMPARISON OPERATORS
*
*/
// column BETWEEN rangeStart and rangeEnd
const $between = (rangeStart, rangeEnd) => ({
$between: { $min: rangeStart, $max: rangeEnd },
});
// column IN (...conditionParams)
const inOperator = (...conditionParams) => ({
$in: conditionParams,
});
// column NOT IN (...conditionParams)
const $notIn = (...conditionParams) => ({
$nin: conditionParams,
});
// column = compareValue
const $eq = (compareValue) => ({ $eq: compareValue });
// column <> compareValue
const $neq = (compareValue) => ({ $neq: compareValue });
// column > compareValue
const $gt = (compareValue) => ({ $gt: compareValue });
// column >= compareValue
const $gte = (compareValue) => ({ $gte: compareValue });
// column < compareValue
const $lt = (compareValue) => ({ $lt: compareValue });
// column <= compareValue
const $lte = (compareValue) => ({ $lte: compareValue });
// column LIKE "%compareValue%"
const $contains = (compareValue) => ({ $contains: compareValue });
// column ILIKE "%compareValue%"
const $icontains = (compareValue) => ({ $icontains: compareValue });
// column LIKE "%compareValue"
const $startsWith = (compareValue) => ({ $startsWith: compareValue });
// column ILIKE "%compareValue"
const $istartsWith = (compareValue) => ({ $istartsWith: compareValue });
// column LIKE "compareValue%"
const $endsWith = (compareValue) => ({ $endsWith: compareValue });
// column ILIKE "compareValue%"
const $iendsWith = (compareValue) => ({ $iendsWith: compareValue });
// column LIKE "compareValue"
const $like = (compareValue) => ({ $like: compareValue });
// column ILIKE "compareValue"
const $ilike = (compareValue) => ({ $ilike: compareValue });
export { $sum, $sum as sum, $count, $count as count, $as, $as as as, $and, $and as and, $or, $or as or, inOperator as $in, inOperator as inOp, $notIn, $notIn as notIn, $between, $between as between, $eq, $eq as eq, $neq, $neq as neq, $gt, $gt as gt, $gte, $gte as gte, $lt, $lt as lt, $lte, $lte as lte, $contains, $contains as contains, $icontains, $icontains as icontains, $startsWith, $startsWith as startsWith, $istartsWith, $istartsWith as istartsWith, $endsWith, $endsWith as endsWith, $iendsWith, $iendsWith as iendsWith, $like, $like as like, $ilike, $ilike as ilike, };