From bb68752c486ec89841c4bd67f9b2bb95cfe4ebc3 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Thu, 20 Jul 2017 16:52:54 +0200 Subject: [PATCH] Document parameters Reviewers: teon.banek, buda Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D575 --- docs/user_technical/open-cypher.md | 33 ++++++++++++++++++++++++ docs/user_technical/upcoming-features.md | 15 ----------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/docs/user_technical/open-cypher.md b/docs/user_technical/open-cypher.md index d00cfb1e6..806638dac 100644 --- a/docs/user_technical/open-cypher.md +++ b/docs/user_technical/open-cypher.md @@ -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 diff --git a/docs/user_technical/upcoming-features.md b/docs/user_technical/upcoming-features.md index e38fb7fc9..1d1584eb0 100644 --- a/docs/user_technical/upcoming-features.md +++ b/docs/user_technical/upcoming-features.md @@ -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