Document parameters

Reviewers: teon.banek, buda

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D575
This commit is contained in:
Mislav Bradac
2017-07-20 16:52:54 +02:00
parent 270ad45552
commit bb68752c48
2 changed files with 33 additions and 15 deletions

View File

@@ -422,6 +422,39 @@ functions.
`endsWith` | Check if the first argument ends with the second.
`contains` | Check if the first argument has an element which is equal to the second argument.
#### Parameters
When automating the queries for Memgraph, it comes in handy to change only
some parts of the query. Usually, these parts are values which are used for
filtering results or similar, while the rest of the query remains the same.
Parameters allow reusing the same query, but with different parameter values.
The syntax uses the `$` symbol to designate a parameter name. We don't allow
old Cypher parameter syntax using curly brace. For example, you can parameterize
filtering a node property:
MATCH (node1 {property: $propertyValue}) RETURN node1
You can use parameters instead of any literal in the query, but not instead of
property maps even though that is allowed in standard openCypher. Following
example is illegal in Memgraph:
MATCH (node1 $propertyValue) RETURN node1
To use parameters with Python driver use following syntax:
session.run('CREATE (alice:Person {name: $name, age: $ageValue}',
name='Alice', ageValue=22)).consume()
To use parameters which names are integers you will need to wrap parameters in
a dictionary and convert them to strings before running a query:
session.run('CREATE (alice:Person {name: $0, age: $1}',
{'0': "Alice", '1': 22})).consume()
To use parameters with some other driver please consult appropriate
documentation.
### Differences
Although we try to implement openCypher query language as closely to the

View File

@@ -69,21 +69,6 @@ paths of length between 2 and 4 can be obtained with a query like:
MATCH (node1) -[*2..4]-> (node2)
#### Parameters
When automating the queries for Memgraph, it comes in handy to change only
some parts of the query. Usually, these parts are values which are used for
filtering results or similar, while the rest of the query remains the same.
Parameters will allow using the same query, but with different parameter
values. The syntax uses the `$` symbol to designate a parameter name. For
example, parameterizing filtering a node property:
MATCH (node1 {property: $propertyValue}) RETURN node1
Other than helping users reuse similar queries, parameters should improve the
performance of running those queries.
#### Functions
Memgraph's openCypher implementation supports the most useful functions, but