UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

338 lines (337 loc) 12.5 kB
"use strict"; /* * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.cypherDatetime = cypherDatetime; exports.cypherDate = cypherDate; exports.cypherLocalDatetime = cypherLocalDatetime; exports.cypherLocalTime = cypherLocalTime; exports.cypherTime = cypherTime; exports.duration = duration; const Literal_1 = require("../../references/Literal"); const normalize_variable_1 = require("../../utils/normalize-variable"); const CypherFunctions_1 = require("./CypherFunctions"); /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime | Cypher Documentation} * @group Functions * @category Temporal */ function cypherDatetime(timezone) { return dateFunction("datetime", timezone); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-timestamp | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.fromepoch = (seconds, nanoseconds) => { const secondsExpr = (0, normalize_variable_1.normalizeExpr)(seconds); const nanosecondsExpr = (0, normalize_variable_1.normalizeExpr)(nanoseconds); return new CypherFunctions_1.CypherFunction("datetime.fromepoch", [secondsExpr, nanosecondsExpr]); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-timestamp | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.fromepochmilis = (seconds, nanoseconds) => { const secondsExpr = (0, normalize_variable_1.normalizeExpr)(seconds); const nanosecondsExpr = (0, normalize_variable_1.normalizeExpr)(nanoseconds); return new CypherFunctions_1.CypherFunction("datetime.fromepochmilis", [secondsExpr, nanosecondsExpr]); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-realtime | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.realtime = (timezone) => { return dateFunction("datetime.realtime", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-statement | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.statement = (timezone) => { return dateFunction("datetime.statement", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-transaction | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.transaction = (timezone) => { return dateFunction("datetime.transaction", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-truncate | Cypher Documentation} * @group Functions * @category Temporal */ cypherDatetime.truncate = (unit, temporalInstantValue, mapOfComponentsTimezone) => { const unitLiteral = new Literal_1.Literal(unit); const params = [unitLiteral, temporalInstantValue]; if (mapOfComponentsTimezone) params.push(mapOfComponentsTimezone); return new CypherFunctions_1.CypherFunction("datetime.truncate", params); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date | Cypher Documentation} * @group Functions * @category Temporal * @example * * Date without parameters: * * ```ts * Cypher.date() * ``` * * _Cypher:_ * ```cypher * date() * ``` * * @example * Date with parameters: * * ```ts * Cypher.date(new Cypher.param('9999-01-01')) * ``` * * _Cypher:_ * ```cypher * date($param1) * ``` */ function cypherDate(timezone) { return dateFunction("date", timezone); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-realtime | Cypher Documentation} * @group Functions * @category Temporal */ cypherDate.realtime = (timezone) => { return dateFunction("date.realtime", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-statement | Cypher Documentation} * @group Functions * @category Temporal */ cypherDate.statement = (timezone) => { return dateFunction("date.statement", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-transaction | Cypher Documentation} * @group Functions * @category Temporal */ cypherDate.transaction = (timezone) => { return dateFunction("date.transaction", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-truncate | Cypher Documentation} * @group Functions * @category Temporal */ cypherDate.truncate = (unit, temporalInstantValue, mapOfComponentsTimezone) => { const unitLiteral = new Literal_1.Literal(unit); const params = [unitLiteral, temporalInstantValue]; if (mapOfComponentsTimezone) params.push(mapOfComponentsTimezone); return new CypherFunctions_1.CypherFunction("date.truncate", params); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime | Cypher Documentation} * @group Functions * @category Temporal */ function cypherLocalDatetime(timezone) { return dateFunction("localdatetime", timezone); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-realtime | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalDatetime.realtime = (timezone) => { return dateFunction("localdatetime.realtime", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-statement | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalDatetime.statement = (timezone) => { return dateFunction("localdatetime.statement", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-transaction | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalDatetime.transaction = (timezone) => { return dateFunction("localdatetime.transaction", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-truncate | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalDatetime.truncate = (unit, temporalInstantValue, mapOfComponentsTimezone) => { const unitLiteral = new Literal_1.Literal(unit); const params = [unitLiteral, temporalInstantValue]; if (mapOfComponentsTimezone) params.push(mapOfComponentsTimezone); return new CypherFunctions_1.CypherFunction("localdatetime.truncate", params); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime | Cypher Documentation} * @group Functions * @category Temporal */ function cypherLocalTime(timezone) { return dateFunction("localtime", timezone); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-realtime | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalTime.realtime = (timezone) => { return dateFunction("localtime.realtime", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-statement | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalTime.statement = (timezone) => { return dateFunction("localtime.statement", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-transaction | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalTime.transaction = (timezone) => { return dateFunction("localtime.transaction", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-truncate | Cypher Documentation} * @group Functions * @category Temporal */ cypherLocalTime.truncate = (unit, temporalInstantValue, mapOfComponentsTimezone) => { const unitLiteral = new Literal_1.Literal(unit); const params = [unitLiteral, temporalInstantValue]; if (mapOfComponentsTimezone) params.push(mapOfComponentsTimezone); return new CypherFunctions_1.CypherFunction("localtime.truncate", params); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time | Cypher Documentation} * @group Functions * @category Temporal */ function cypherTime(timezone) { return dateFunction("time", timezone); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-realtime | Cypher Documentation} * @group Functions * @category Temporal */ cypherTime.realtime = (timezone) => { return dateFunction("time.realtime", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-statement | Cypher Documentation} * @group Functions * @category Temporal */ cypherTime.statement = (timezone) => { return dateFunction("time.statement", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-transaction | Cypher Documentation} * @group Functions * @category Temporal */ cypherTime.transaction = (timezone) => { return dateFunction("time.transaction", timezone); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-truncate | Cypher Documentation} * @group Functions * @category Temporal */ cypherTime.truncate = (unit, temporalInstantValue, mapOfComponentsTimezone) => { const unitLiteral = new Literal_1.Literal(unit); const params = [unitLiteral, temporalInstantValue]; if (mapOfComponentsTimezone) params.push(mapOfComponentsTimezone); return new CypherFunctions_1.CypherFunction("time.truncate", params); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration | Cypher Documentation} * @group Functions * @category Temporal */ function duration(components) { return new CypherFunctions_1.CypherFunction("duration", [components]); } /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-between | Cypher Documentation} * @group Functions * @category Temporal */ duration.between = (instant1, instant2) => { return new CypherFunctions_1.CypherFunction("duration.between", [instant1, instant2]); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-inmonths | Cypher Documentation} * @group Functions * @category Temporal */ duration.inMonths = (instant1, instant2) => { return new CypherFunctions_1.CypherFunction("duration.inMonths", [instant1, instant2]); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-indays | Cypher Documentation} * @group Functions * @category Temporal */ duration.inDays = (instant1, instant2) => { return new CypherFunctions_1.CypherFunction("duration.inDays", [instant1, instant2]); }; /** * @see {@link https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-inseconds | Cypher Documentation} * @group Functions * @category Temporal */ duration.inSeconds = (instant1, instant2) => { return new CypherFunctions_1.CypherFunction("duration.inSeconds", [instant1, instant2]); }; // Handles optional timezone param before creating a function function dateFunction(name, timezone) { return new CypherFunctions_1.CypherFunction(name, timezone ? [timezone] : undefined); }