Skip to content

Commit 507934c

Browse files
committed
Remove extra parameters in Foreach
1 parent 5d4d689 commit 507934c

File tree

4 files changed

+47
-102
lines changed

4 files changed

+47
-102
lines changed

.changeset/violet-sloths-hug.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
"@neo4j/cypher-builder": major
3+
---
4+
5+
Remove extra parameters in `Cypher.Foreach` in favor of methods `in` and `do`.
6+
7+
For example, to create the following Cypher:
8+
9+
```cypher
10+
FOREACH (var0 IN [1, 2, 3] |
11+
CREATE (this1:Movie)
12+
SET
13+
this1.id = var0
14+
)
15+
```
16+
17+
_before_
18+
19+
```js
20+
const list = new Cypher.Literal([1, 2, 3]);
21+
const variable = new Cypher.Variable();
22+
23+
const movieNode = new Cypher.Node();
24+
const createMovie = new Cypher.Create(new Cypher.Pattern(movieNode, { labels: ["Movie"] })).set([
25+
movieNode.property("id"),
26+
variable,
27+
]);
28+
29+
const foreachClause = new Cypher.Foreach(variable, list, createMovie);
30+
```
31+
32+
_after_
33+
34+
```js
35+
const list = new Cypher.Literal([1, 2, 3]);
36+
const variable = new Cypher.Variable();
37+
38+
const movieNode = new Cypher.Node();
39+
const createMovie = new Cypher.Create(new Cypher.Pattern(movieNode, { labels: ["Movie"] })).set([
40+
movieNode.property("id"),
41+
variable,
42+
]);
43+
44+
const foreachClause = new Cypher.Foreach(variable).in(list).do(createMovie);
45+
```

src/clauses/Foreach.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ export class Foreach extends Clause {
5151
private mapClause: ForeachClauses | undefined;
5252

5353
constructor(variable: Variable);
54-
/** @deprecated Use `in` and `do` instead of passing the constructor */
55-
constructor(variable: Variable, listExpr: Expr, mapClause: ForeachClauses);
56-
constructor(variable: Variable, listExpr?: Expr, mapClause?: ForeachClauses) {
54+
constructor(variable: Variable) {
5755
super();
5856
this.variable = variable;
59-
this.listExpr = listExpr;
60-
this.mapClause = mapClause;
6157
}
6258

6359
public in(listExpr: Expr): this {

tests/clause-chaining.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe("Clause chaining", () => {
9999
const movieNode = new Cypher.Node();
100100
const createMovie = new Cypher.Create(new Cypher.Pattern(movieNode)).set([movieNode.property("id"), variable]);
101101

102-
const clause = new Cypher.Foreach(variable, list, createMovie);
102+
const clause = new Cypher.Foreach(variable).in(list).do(createMovie);
103103

104104
it.each(["return", "remove", "set", "delete", "detachDelete", "with", "merge", "create"] as const)(
105105
"Foreach.%s",

tests/deprecated/Foreach.test.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)