@neo4j/cypher-builder
Version:
A programmatic API for building Cypher queries for Neo4j
58 lines (57 loc) • 2.05 kB
JavaScript
;
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithOrder = void 0;
const OrderBy_1 = require("../../sub-clauses/OrderBy");
const Mixin_1 = require("../Mixin");
const DEFAULT_ORDER = "ASC";
class WithOrder extends Mixin_1.Mixin {
orderByStatement;
/** Add an `ORDER BY` subclause. Note that `ASC` is the default sorting order
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/order-by/ | Cypher Documentation}
*/
orderBy(...exprs) {
const normalizedExprs = exprs.map((rawExpr) => {
if (Array.isArray(rawExpr)) {
return [rawExpr[0], rawExpr[1] ?? DEFAULT_ORDER];
}
return [rawExpr, DEFAULT_ORDER];
});
const orderByStatement = this.getOrCreateOrderBy();
orderByStatement.addOrderElements(normalizedExprs);
return this;
}
/** Add a `SKIP` subclause.
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/skip/ | Cypher Documentation}
*/
skip(value) {
const orderByStatement = this.getOrCreateOrderBy();
orderByStatement.skip(value);
return this;
}
/** Add a `OFFSET` subclause. An alias to `SKIP`
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/skip/#offset-synonym | Cypher Documentation}
* @since Neo4j 5.24
*/
offset(value) {
const orderByStatement = this.getOrCreateOrderBy();
orderByStatement.offset(value);
return this;
}
/** Add a `LIMIT` subclause.
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/limit/ | Cypher Documentation}
*/
limit(value) {
const orderByStatement = this.getOrCreateOrderBy();
orderByStatement.limit(value);
return this;
}
getOrCreateOrderBy() {
this.orderByStatement ??= new OrderBy_1.OrderBy();
return this.orderByStatement;
}
}
exports.WithOrder = WithOrder;