@neo4j/cypher-builder
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -42,3 +42,3 @@ "use strict"; | ||
constructor(clause, variables, many) { | ||
super(`apoc.cypher.runFirstColumn${many ? "Many" : "Single"}`); | ||
super(`apoc.cypher.runFirstColumn${many ? "Many" : "Single"}`); // Note: this argument is never used | ||
this.innerClause = clause; | ||
@@ -45,0 +45,0 @@ this.variables = this.parseVariablesInput(variables); |
@@ -5,5 +5,2 @@ import type { Order } from "../sub-clauses/OrderBy"; | ||
import type { Expr } from "../../types"; | ||
import type { Param } from "../../references/Param"; | ||
import type { Literal } from "../../references/Literal"; | ||
import type { Integer } from "neo4j-driver"; | ||
export declare abstract class WithOrder extends ClauseMixin { | ||
@@ -18,8 +15,8 @@ protected orderByStatement: OrderBy | undefined; | ||
*/ | ||
skip(value: number | Param<Integer> | Param<number> | Literal<number>): this; | ||
skip(value: number | Expr): this; | ||
/** Add a `LIMIT` subclause. | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/clauses/limit/) | ||
*/ | ||
limit(value: number | Param<Integer> | Param<number> | Literal<number>): this; | ||
limit(value: number | Expr): this; | ||
private getOrCreateOrderBy; | ||
} |
@@ -37,3 +37,3 @@ export { Match, OptionalMatch } from "./clauses/Match"; | ||
export * from "./expressions/functions/scalar"; | ||
export { count, min, max, avg, sum, collect } from "./expressions/functions/aggregation"; | ||
export { count, min, max, avg, sum, collect, percentileCont, percentileDisc, stDev, stDevP, } from "./expressions/functions/aggregation"; | ||
export * from "./expressions/functions/string"; | ||
@@ -40,0 +40,0 @@ export * from "./expressions/functions/list"; |
@@ -48,3 +48,3 @@ "use strict"; | ||
exports.in = exports.isNotNull = exports.isNull = exports.lte = exports.lt = exports.gte = exports.gt = exports.neq = exports.eq = exports.xor = exports.not = exports.and = exports.or = exports.MapProjection = exports.Map = exports.List = exports.PatternComprehension = exports.ListComprehension = exports.apoc = exports.Case = exports.Count = exports.Exists = exports.Property = exports.NamedPath = exports.Path = exports.Null = exports.Literal = exports.Variable = exports.NamedVariable = exports.NamedParam = exports.Param = exports.NamedRelationship = exports.Relationship = exports.NamedNode = exports.Node = exports.labelExpr = exports.Pattern = exports.concat = exports.Foreach = exports.Union = exports.Unwind = exports.With = exports.RawCypher = exports.Return = exports.Use = exports.Call = exports.Merge = exports.Create = exports.OptionalMatch = exports.Match = void 0; | ||
exports.utils = exports.db = exports.VoidProcedure = exports.Procedure = exports.isEmpty = exports.none = exports.single = exports.exists = exports.all = exports.any = exports.graph = exports.collect = exports.sum = exports.avg = exports.max = exports.min = exports.count = exports.time = exports.localdatetime = exports.localtime = exports.date = exports.datetime = exports.Function = exports.pow = exports.mod = exports.multiply = exports.divide = exports.minus = exports.plus = exports.matches = exports.endsWith = exports.startsWith = exports.contains = void 0; | ||
exports.utils = exports.db = exports.VoidProcedure = exports.Procedure = exports.isEmpty = exports.none = exports.single = exports.exists = exports.all = exports.any = exports.graph = exports.stDevP = exports.stDev = exports.percentileDisc = exports.percentileCont = exports.collect = exports.sum = exports.avg = exports.max = exports.min = exports.count = exports.time = exports.localdatetime = exports.localtime = exports.date = exports.datetime = exports.Function = exports.pow = exports.mod = exports.multiply = exports.divide = exports.minus = exports.plus = exports.matches = exports.endsWith = exports.startsWith = exports.contains = void 0; | ||
// Clauses | ||
@@ -167,2 +167,6 @@ var Match_1 = require("./clauses/Match"); | ||
Object.defineProperty(exports, "collect", { enumerable: true, get: function () { return aggregation_1.collect; } }); | ||
Object.defineProperty(exports, "percentileCont", { enumerable: true, get: function () { return aggregation_1.percentileCont; } }); | ||
Object.defineProperty(exports, "percentileDisc", { enumerable: true, get: function () { return aggregation_1.percentileDisc; } }); | ||
Object.defineProperty(exports, "stDev", { enumerable: true, get: function () { return aggregation_1.stDev; } }); | ||
Object.defineProperty(exports, "stDevP", { enumerable: true, get: function () { return aggregation_1.stDevP; } }); | ||
__exportStar(require("./expressions/functions/string"), exports); | ||
@@ -169,0 +173,0 @@ __exportStar(require("./expressions/functions/list"), exports); |
@@ -40,2 +40,26 @@ import type { CypherEnvironment } from "../../Environment"; | ||
export declare function collect(expr: Expr): CypherAggregationFunction; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-percentilecont) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
export declare function percentileCont(expr: Expr, percentile: number | Expr): CypherAggregationFunction; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-percentiledisc) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
export declare function percentileDisc(expr: Expr, percentile: number | Expr): CypherAggregationFunction; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-stdev) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
export declare function stDev(expr: Expr): CypherAggregationFunction; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-stdevp) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
export declare function stDevP(expr: Expr): CypherAggregationFunction; | ||
/** Represents a Cypher Aggregation function | ||
@@ -52,3 +76,3 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating) | ||
*/ | ||
constructor(name: string, param: Expr | "*"); | ||
constructor(name: string, params: Array<Expr | "*">); | ||
/** | ||
@@ -55,0 +79,0 @@ * Adds DISTINCT to remove duplicates on the aggregation functions |
@@ -21,3 +21,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CypherAggregationFunction = exports.collect = exports.sum = exports.avg = exports.max = exports.min = exports.count = void 0; | ||
exports.CypherAggregationFunction = exports.stDevP = exports.stDev = exports.percentileDisc = exports.percentileCont = exports.collect = exports.sum = exports.avg = exports.max = exports.min = exports.count = void 0; | ||
const normalize_variable_1 = require("../../utils/normalize-variable"); | ||
const CypherFunctions_1 = require("./CypherFunctions"); | ||
@@ -30,3 +31,3 @@ /** | ||
function count(expr) { | ||
return new CypherAggregationFunction("count", expr); | ||
return new CypherAggregationFunction("count", [expr]); | ||
} | ||
@@ -40,3 +41,3 @@ exports.count = count; | ||
function min(expr) { | ||
return new CypherAggregationFunction("min", expr); | ||
return new CypherAggregationFunction("min", [expr]); | ||
} | ||
@@ -50,3 +51,3 @@ exports.min = min; | ||
function max(expr) { | ||
return new CypherAggregationFunction("max", expr); | ||
return new CypherAggregationFunction("max", [expr]); | ||
} | ||
@@ -60,3 +61,3 @@ exports.max = max; | ||
function avg(expr) { | ||
return new CypherAggregationFunction("avg", expr); | ||
return new CypherAggregationFunction("avg", [expr]); | ||
} | ||
@@ -70,3 +71,3 @@ exports.avg = avg; | ||
function sum(expr) { | ||
return new CypherAggregationFunction("sum", expr); | ||
return new CypherAggregationFunction("sum", [expr]); | ||
} | ||
@@ -80,5 +81,43 @@ exports.sum = sum; | ||
function collect(expr) { | ||
return new CypherAggregationFunction("collect", expr); | ||
return new CypherAggregationFunction("collect", [expr]); | ||
} | ||
exports.collect = collect; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-percentilecont) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
function percentileCont(expr, percentile) { | ||
const normalizedPercentile = (0, normalize_variable_1.normalizeExpr)(percentile); | ||
return new CypherAggregationFunction("percentileCont", [expr, normalizedPercentile]); | ||
} | ||
exports.percentileCont = percentileCont; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-percentiledisc) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
function percentileDisc(expr, percentile) { | ||
const normalizedPercentile = (0, normalize_variable_1.normalizeExpr)(percentile); | ||
return new CypherAggregationFunction("percentileDisc", [expr, normalizedPercentile]); | ||
} | ||
exports.percentileDisc = percentileDisc; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-stdev) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
function stDev(expr) { | ||
return new CypherAggregationFunction("stDev", [expr]); | ||
} | ||
exports.stDev = stDev; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-stdevp) | ||
* @group Cypher Functions | ||
* @category Aggregations | ||
*/ | ||
function stDevP(expr) { | ||
return new CypherAggregationFunction("stDevP", [expr]); | ||
} | ||
exports.stDevP = stDevP; | ||
/** Represents a Cypher Aggregation function | ||
@@ -93,12 +132,14 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/aggregating) | ||
*/ | ||
constructor(name, param) { | ||
constructor(name, params) { | ||
super(name); | ||
this.hasDistinct = false; | ||
this.hasStar = false; | ||
if (param === "*") { | ||
this.hasStar = true; | ||
for (const param of params) { | ||
if (param === "*") { | ||
this.hasStar = true; | ||
} | ||
else { | ||
this.addParam(param); | ||
} | ||
} | ||
else { | ||
this.addParam(param); | ||
} | ||
} | ||
@@ -105,0 +146,0 @@ /** |
@@ -9,2 +9,6 @@ import type { Expr } from "../../types"; | ||
export declare function point(variable: Expr): CypherFunction; | ||
export declare namespace point { | ||
var distance: (lexpr: Expr, rexpr: Expr) => CypherFunction; | ||
var withinBBox: (point: Expr, lexpr: Expr, rexpr: Expr) => CypherFunction; | ||
} | ||
/** | ||
@@ -14,3 +18,3 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/4.3/functions/spatial/#functions-distance) | ||
* @category Spatial | ||
* @deprecated No longer supported in Neo4j 5. Use {@link pointDistance} instead. | ||
* @deprecated No longer supported in Neo4j 5. Use {@link point.distance} instead. | ||
*/ | ||
@@ -23,3 +27,4 @@ export declare function distance(lexpr: Expr, rexpr: Expr): CypherFunction; | ||
* @example Generated Cypher: `point.distance(point1, point2)` | ||
* @deprecated Use {@link point.distance} instead | ||
*/ | ||
export declare function pointDistance(lexpr: Expr, rexpr: Expr): CypherFunction; |
@@ -36,3 +36,3 @@ "use strict"; | ||
* @category Spatial | ||
* @deprecated No longer supported in Neo4j 5. Use {@link pointDistance} instead. | ||
* @deprecated No longer supported in Neo4j 5. Use {@link point.distance} instead. | ||
*/ | ||
@@ -48,2 +48,3 @@ function distance(lexpr, rexpr) { | ||
* @example Generated Cypher: `point.distance(point1, point2)` | ||
* @deprecated Use {@link point.distance} instead | ||
*/ | ||
@@ -54,1 +55,18 @@ function pointDistance(lexpr, rexpr) { | ||
exports.pointDistance = pointDistance; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/spatial/#functions-distance) | ||
* @group Cypher Functions | ||
* @category Spatial | ||
* @example Generated Cypher: `point.distance(point1, point2)` | ||
*/ | ||
point.distance = (lexpr, rexpr) => { | ||
return new CypherFunctions_1.CypherFunction("point.distance", [lexpr, rexpr]); | ||
}; | ||
/** | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/functions/spatial/#functions-withinBBox) | ||
* @group Cypher Functions | ||
* @category Spatial | ||
*/ | ||
point.withinBBox = (point, lexpr, rexpr) => { | ||
return new CypherFunctions_1.CypherFunction("point.withinBBox", [point, lexpr, rexpr]); | ||
}; |
@@ -31,3 +31,3 @@ import type { Environment } from "../.."; | ||
*/ | ||
declare function labelAnd(left: Label, right: Label, ...extra: Label[]): LabelExpr; | ||
declare function labelAnd(...labels: Label[]): LabelExpr; | ||
/** Generates an `|` operator between labels or types | ||
@@ -38,3 +38,3 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#label-expressions) | ||
*/ | ||
declare function labelOr(left: Label, right: Label, ...extra: Label[]): LabelExpr; | ||
declare function labelOr(...labels: Label[]): LabelExpr; | ||
/** Generates an `!` operator for a label or type | ||
@@ -41,0 +41,0 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#label-expressions) |
@@ -34,2 +34,4 @@ "use strict"; | ||
const labelStrs = this.labels.map((l) => this.compileLabel(l, env)); | ||
if (labelStrs.length === 0) | ||
return ""; | ||
return `(${labelStrs.join(this.operator)})`; | ||
@@ -67,4 +69,4 @@ } | ||
*/ | ||
function labelAnd(left, right, ...extra) { | ||
return new BinaryLabelExpr("&", [left, right, ...extra]); | ||
function labelAnd(...labels) { | ||
return new BinaryLabelExpr("&", labels); | ||
} | ||
@@ -76,4 +78,4 @@ /** Generates an `|` operator between labels or types | ||
*/ | ||
function labelOr(left, right, ...extra) { | ||
return new BinaryLabelExpr("|", [left, right, ...extra]); | ||
function labelOr(...labels) { | ||
return new BinaryLabelExpr("|", labels); | ||
} | ||
@@ -80,0 +82,0 @@ /** Generates an `!` operator for a label or type |
@@ -73,2 +73,5 @@ "use strict"; | ||
if (labels instanceof label_expressions_1.LabelExpr) { | ||
const labelsStr = labels.getCypher(env); | ||
if (!labelsStr) | ||
return ""; | ||
return `:${labels.getCypher(env)}`; | ||
@@ -75,0 +78,0 @@ } |
{ | ||
"name": "@neo4j/cypher-builder", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A programmatic API for building Cypher queries for Neo4j", | ||
@@ -48,3 +48,3 @@ "exports": "./dist/index.js", | ||
"@types/jest": "29.5.3", | ||
"@types/node": "20.4.2", | ||
"@types/node": "20.4.5", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
@@ -55,3 +55,3 @@ "@typescript-eslint/parser": "^6.0.0", | ||
"expect-type": "0.16.0", | ||
"jest": "29.6.1", | ||
"jest": "29.6.2", | ||
"jest-extended": "4.0.0", | ||
@@ -58,0 +58,0 @@ "neo4j-driver": "^5.9.2", |
@@ -10,2 +10,3 @@ # Cypher Builder | ||
- [Documentation](https://neo4j.github.io/cypher-builder/cypher-builder/current/) | ||
- [Discussions](https://github.com/neo4j/cypher-builder/discussions) | ||
@@ -12,0 +13,0 @@ ```typescript |
342815
8492
52