Skip to content

Commit 01692d0

Browse files
committed
Simplify cypher variable handling by not even adding them to the bag
Previously, they would be kept unique: active, active2, active3. But then stripped out on `getParams`, so this was wasted effort. So this is faster and less confusing.
1 parent f766b07 commit 01692d0

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/core/database/query-augmentation/condition-variables.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* This file patches pattern conditions to support referencing existing variables.
33
* This is achieved by wrapping the variable name in a `variable()` call.
44
*/
5-
import { mapValues } from '@seedcompany/common';
65
import { Clause, NodePattern } from 'cypher-query-builder';
76
import type { Pattern as TSPattern } from 'cypher-query-builder/dist/typings/clauses/pattern';
87
import type {
@@ -37,24 +36,15 @@ export class Variable extends Parameter {
3736
*/
3837
export const variable = (expression: string) => new Variable(expression);
3938

39+
const origAddParam = ParameterBag.prototype.addParam;
4040
ParameterBag.prototype.addParam = function addParam(
4141
this: TSParameterBag,
4242
value: any | Variable,
4343
name?: string,
4444
) {
45-
const actualName = this.getName(name);
46-
const param =
47-
value instanceof Variable
48-
? new Variable(value.value, actualName)
49-
: new Parameter(actualName, value);
50-
this.parameterMap[actualName] = param;
51-
return param;
52-
};
53-
54-
ParameterBag.prototype.getParams = function getParams(this: TSParameterBag) {
55-
return mapValues(this.parameterMap, (_, param, { SKIP }) =>
56-
param instanceof Variable ? SKIP : param.value,
57-
).asRecord;
45+
return value instanceof Variable
46+
? value
47+
: origAddParam.call(this, value, name);
5848
};
5949

6050
Pattern.prototype.setExpandedConditions = function (

0 commit comments

Comments
 (0)