@neo4j/cypher-builder
Advanced tools
Comparing version 1.14.0 to 1.15.0
@@ -15,2 +15,6 @@ import type { CypherEnvironment } from "../Environment"; | ||
} | ||
type InTransactionConfig = { | ||
ofRows?: number; | ||
onError?: "continue" | "break" | "fail"; | ||
}; | ||
/** | ||
@@ -23,2 +27,3 @@ * @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/) | ||
private _importWith; | ||
private inTransactionsConfig?; | ||
private _usingImportWith; | ||
@@ -30,2 +35,3 @@ constructor(subquery: Clause); | ||
importWith(...params: Array<Variable | "*">): this; | ||
inTransactions(config?: InTransactionConfig): this; | ||
/** @deprecated Use {@link importWith} instead */ | ||
@@ -36,2 +42,5 @@ innerWith(...params: Array<Variable | "*">): this; | ||
private getSubqueryCypher; | ||
private generateInTransactionStr; | ||
private getOnErrorStr; | ||
} | ||
export {}; |
@@ -71,2 +71,6 @@ "use strict"; | ||
} | ||
inTransactions(config = {}) { | ||
this.inTransactionsConfig = config; | ||
return this; | ||
} | ||
/** @deprecated Use {@link importWith} instead */ | ||
@@ -89,5 +93,6 @@ innerWith(...params) { | ||
const setCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.setSubClause, env, { prefix: "\n" }); | ||
const inTransactionCypher = this.generateInTransactionStr(); | ||
const inCallBlock = `${importWithCypher}${subQueryStr}`; | ||
const nextClause = this.compileNextClause(env); | ||
return `CALL {\n${(0, pad_block_1.padBlock)(inCallBlock)}\n}${setCypher}${removeCypher}${deleteCypher}${nextClause}`; | ||
return `CALL {\n${(0, pad_block_1.padBlock)(inCallBlock)}\n}${inTransactionCypher}${setCypher}${removeCypher}${deleteCypher}${nextClause}`; | ||
} | ||
@@ -102,2 +107,23 @@ getSubqueryCypher(env, importWithCypher) { | ||
} | ||
generateInTransactionStr() { | ||
if (!this.inTransactionsConfig) { | ||
return ""; | ||
} | ||
const rows = this.inTransactionsConfig.ofRows; | ||
const error = this.inTransactionsConfig.onError; | ||
const ofRowsStr = rows ? ` OF ${rows} ROWS` : ""; | ||
const onErrorStr = error ? ` ON ERROR ${this.getOnErrorStr(error)}` : ""; | ||
return ` IN TRANSACTIONS${ofRowsStr}${onErrorStr}`; | ||
} | ||
getOnErrorStr(err) { | ||
const errorMap = { | ||
continue: "CONTINUE", | ||
break: "BREAK", | ||
fail: "FAIL", | ||
}; | ||
if (!errorMap[err]) { | ||
throw new Error(`Incorrect ON ERROR option ${err}`); | ||
} | ||
return errorMap[err]; | ||
} | ||
}; | ||
@@ -104,0 +130,0 @@ exports.Call = Call; |
{ | ||
"name": "@neo4j/cypher-builder", | ||
"version": "1.14.0", | ||
"version": "1.15.0", | ||
"description": "A programmatic API for building Cypher queries for Neo4j", | ||
@@ -5,0 +5,0 @@ "exports": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
419331
10247