Skip to content

Commit bb90dcb

Browse files
Expand and move query parameters.
1 parent 8b8a006 commit bb90dcb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

modules/ROOT/pages/query.adoc

+41
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,47 @@ This means that queries should fit on a single line.
8888
You can replace line breaks with spaces, as Cypher parses them equivalently.
8989
====
9090

91+
92+
== Query parameters
93+
94+
Do not hardcode or concatenate parameters directly into queries.
95+
Instead, always use placeholders and specify the link:{neo4j-docs-base-uri}/cypher-manual/current/syntax/parameters/[Cypher parameters].
96+
This is for:
97+
98+
1. *performance benefits*: Neo4j compiles and caches queries, but can only do so if the query structure is unchanged;
99+
2. *security reasons*: see link:https://neo4j.com/developer/kb/protecting-against-cypher-injection/[protecting against Cypher injection].
100+
101+
.Do -- Use query parameters
102+
[source, JSON]
103+
----
104+
{
105+
"statements": [
106+
{
107+
"statement": "MERGE (n:Person {name: $name, age: $age}) RETURN n",
108+
"parameters": {
109+
"name": "Alice",
110+
"age": 42
111+
}
112+
}
113+
]
114+
}
115+
----
116+
117+
.Do not -- Embed literals in query
118+
[source, JSON]
119+
----
120+
{
121+
"statements": [
122+
{
123+
"statement": "MERGE (n:Person {name: 'Alice', age: 42}) RETURN n",
124+
}
125+
]
126+
}
127+
----
128+
129+
See link:{neo4j-docs-base-uri}/cypher-manual/current/syntax/parameters/[Cypher Manual -> Parameters] for more information.
130+
131+
91132
== Execute multiple queries
92133

93134
You can send multiple Cypher statements in the same request.

0 commit comments

Comments
 (0)