-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple expressions in case
- Loading branch information
1 parent
4190597
commit 5fa3f51
Showing
5 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@neo4j/cypher-builder": patch | ||
--- | ||
|
||
Add support for multiple expressions on the simple CASE: | ||
|
||
```cypher | ||
matchClause.return( | ||
new Cypher.Case(person.property("eyes")) | ||
.when(new Cypher.Literal("brown"), new Cypher.Literal("hazel")) | ||
.then(new Cypher.Literal(2)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
docs/modules/ROOT/pages/how-to/conditional-expressions.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[[conditional-expressions]] | ||
:description: This page describes how to create conditional expressions with CASE. | ||
= Conditional Expressions (CASE) | ||
|
||
This page describes how to create link:https://neo4j.com/docs/cypher-manual/current/queries/case/[`CASE`] expressions in Cypher with Cypher Builder. | ||
|
||
|
||
== Simple CASE | ||
|
||
THe simple `CASE` form compares a single expressions against multiple values. It can be constructed with the `Case` class by passing the expression to be compared the constructor: | ||
|
||
|
||
[source, javascript] | ||
---- | ||
const person = new Cypher.Node(); | ||
new Cypher.Case(person.property("eyes")) | ||
.when(new Cypher.Literal("blue")).then(new Cypher.Literal(1)) | ||
.when(new Cypher.Literal("brown"), new Cypher.Literal("hazel")).then(new Cypher.Literal(2)) | ||
.else(new Cypher.Literal(3)) | ||
---- | ||
|
||
The resulting Cypher, note that `END` is added automatically: | ||
|
||
[source, cypher] | ||
---- | ||
CASE n.eyes | ||
WHEN 'blue' THEN 1 | ||
WHEN 'brown', 'hazel' THEN 2 | ||
ELSE 3 | ||
END | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters