Skip to content

Commit f008d52

Browse files
committed
readme
1 parent 3b50ada commit f008d52

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cypher.ScriptGenerator
22

3-
A .NET library for generating [Cypher](https://neo4j.com/docs/cypher-manual/current/) scripts for Neo4j — supporting **CREATE**, **MERGE**, **DELETE**, **indexes**, and **constraints**.
3+
A .NET library for generating [Cypher](https://neo4j.com/docs/cypher-manual/current/) scripts for Neo4j — supporting **CREATE**, **MERGE**, **DELETE**, **UNWIND**, **indexes**, and **constraints**.
44

55
## Installation
66

@@ -25,6 +25,7 @@ services.AddSingleton<INodeGenerator, NodeGenerator>();
2525
services.AddSingleton<IRelationshipGenerator, RelationshipGenerator>();
2626
services.AddSingleton<IIndexGenerator, IndexGenerator>();
2727
services.AddSingleton<IConstraintGenerator, ConstraintGenerator>();
28+
services.AddSingleton<IUnwindGenerator, UnwindGenerator>();
2829
```
2930

3031
| Class | Interface |
@@ -33,6 +34,7 @@ services.AddSingleton<IConstraintGenerator, ConstraintGenerator>();
3334
| `RelationshipGenerator` | `IRelationshipGenerator`|
3435
| `IndexGenerator` | `IIndexGenerator` |
3536
| `ConstraintGenerator` | `IConstraintGenerator` |
37+
| `UnwindGenerator` | `IUnwindGenerator` |
3638

3739
---
3840

@@ -354,6 +356,83 @@ generator.Drop("person_name_unique");
354356

355357
---
356358

359+
## UNWIND
360+
361+
Use `UnwindGenerator` (or `IUnwindGenerator`) para operações em lote — itera sobre uma lista e aplica `MERGE` em cada elemento. Ideal para importações de dados.
362+
363+
### UnwindDefinition model
364+
365+
| Property | Type | Description |
366+
|-------------|----------|--------------------------------------------------------------------|
367+
| `Parameter` | `string` | Lista a iterar: parâmetro (`"$nodes"`) ou literal (`"[1, 2, 3]"`) |
368+
| `Alias` | `string` | Nome da variável para cada elemento (`"row"`, `"item"`, `"node"`) |
369+
370+
### UNWIND + MERGE nodes
371+
372+
```csharp
373+
var generator = new UnwindGenerator();
374+
375+
// Merge simples com SET
376+
generator.MergeNodes(
377+
new UnwindDefinition { Parameter = "$nodes", Alias = "row" },
378+
label: "Person",
379+
matchProperty: "id",
380+
setProperties: new List<string> { "name", "age" }
381+
);
382+
// → UNWIND $nodes AS row
383+
// MERGE (n:Person {id: row.id})
384+
// SET n.name = row.name, n.age = row.age
385+
386+
// Com ON CREATE SET e ON MATCH SET
387+
generator.MergeNodes(
388+
new UnwindDefinition { Parameter = "$nodes", Alias = "row" },
389+
label: "Person",
390+
matchProperty: "id",
391+
setProperties: new List<string> { "name" },
392+
onCreateProperties: new List<string> { "createdAt" },
393+
onMatchProperties: new List<string> { "updatedAt" }
394+
);
395+
// → UNWIND $nodes AS row
396+
// MERGE (n:Person {id: row.id})
397+
// SET n.name = row.name
398+
// ON CREATE SET n.createdAt = row.createdAt
399+
// ON MATCH SET n.updatedAt = row.updatedAt
400+
```
401+
402+
### UNWIND + MERGE relationships
403+
404+
```csharp
405+
// Merge simples de relacionamentos
406+
generator.MergeRelationships(
407+
new UnwindDefinition { Parameter = "$rows", Alias = "row" },
408+
leftLabel: "Person", leftMatchProperty: "id",
409+
rightLabel: "Company", rightMatchProperty: "id",
410+
relationshipLabel: "WORKS_AT"
411+
);
412+
// → UNWIND $rows AS row
413+
// MATCH (a:Person {id: row.id})
414+
// MATCH (b:Company {id: row.id})
415+
// MERGE (a)-[:WORKS_AT]->(b)
416+
417+
// Com ON CREATE SET e ON MATCH SET
418+
generator.MergeRelationships(
419+
new UnwindDefinition { Parameter = "$rows", Alias = "row" },
420+
leftLabel: "Person", leftMatchProperty: "id",
421+
rightLabel: "Company", rightMatchProperty: "id",
422+
relationshipLabel: "WORKS_AT",
423+
onCreateProperties: new List<string> { "since" },
424+
onMatchProperties: new List<string> { "updatedAt" }
425+
);
426+
// → UNWIND $rows AS row
427+
// MATCH (a:Person {id: row.id})
428+
// MATCH (b:Company {id: row.id})
429+
// MERGE (a)-[r:WORKS_AT]->(b)
430+
// ON CREATE SET r.since = row.since
431+
// ON MATCH SET r.updatedAt = row.updatedAt
432+
```
433+
434+
---
435+
357436
## Supported property types
358437

359438
The following C# types are supported as property values:
@@ -379,3 +458,4 @@ The project has full unit test coverage. See the test files for all scenarios:
379458
- [RelationshipGeneratorTest.cs](https://github.com/IgorRozani/Cypher.ScriptGenerator/blob/master/Cypher.ScriptGenerator.Test/Generators/RelationshipGeneratorTest.cs)
380459
- [IndexGeneratorTest.cs](https://github.com/IgorRozani/Cypher.ScriptGenerator/blob/master/Cypher.ScriptGenerator.Test/Generators/IndexGeneratorTest.cs)
381460
- [ConstraintGeneratorTest.cs](https://github.com/IgorRozani/Cypher.ScriptGenerator/blob/master/Cypher.ScriptGenerator.Test/Generators/ConstraintGeneratorTest.cs)
461+
- [UnwindGeneratorTest.cs](https://github.com/IgorRozani/Cypher.ScriptGenerator/blob/master/Cypher.ScriptGenerator.Test/Generators/UnwindGeneratorTest.cs)

0 commit comments

Comments
 (0)