Comments (2)
Hi, @Tshimanga!
The question is more about Cypher statement system then the driver itself. So, let us try to understand how this things works. There are no any string interpolation or something like this. Driver itself follow the protocol and do not provide any ORM or template system.
Each query is just a constant string, that is sent to the server. So we can run simple queries, that are presented by Text
datatype, like "MATCH (n:Person {name: "Carl"}) RETURN n"
. So, this query will run just the same operation each time it is sent.
But of course we want some dynamic queries, where we can change values as we need:
"MATCH (n:Person {name: "Carl"}) RETURN n"
"MATCH (n:Person {name: "John"}) RETURN n"
- etc
To make this possible we may try to construct a newText
request each time we send a request, like:
makeCypher :: String -> Text
makeCypher name = T.pack $ ""MATCH (n:Person {name: \"" ++ name ++ "\"}) RETURN n"
But this way is ugly in many cases. First, we have to construct this string and it is unpleasant itself. And second, neo4j server cannot cache such queries, as it see them as different statements (that is why usage of string interpolation is a bad idea here). To fix this problem we can use query parameters.
Neo4j lets us to send a statement and parameters separately. So it will cache our statements and just change some values in them. Parameters are presented as a map with string keys. So, we can place some {hole}
s inside our statement and the name of the hole will we a key in such map. The system is pretty reach, as it let us use not only primitive types, but also maps and lists. Here is some examples:
let name = T "Carl"
let paramsMap = M (fromList [("name", name)])
queryP "MATCH (n:Person) WHERE n.name = {name} RETURN n" (fromList [("name", name)])
queryP "MATCH (n:Person {params}) RETURN n" (fromList [("params", paramsMap)])
I hope, it has clarified the situation a bit.
from hasbolt.
Thanks @zmactep
from hasbolt.
Related Issues (20)
- Compiler error on versions > 0.1.1.3 HOT 2
- log output HOT 1
- error: Variable not in scope: def HOT 3
- Support for transactions HOT 6
- Neo4j 4 drops bolt version 1, perhaps default to higher version? HOT 8
- Show, Read instance to BoltCfg HOT 1
- profiling Cypher queries
- Bolt protocol 4+ support (with poll) HOT 11
- Sending queries with parameters not in map hangs HOT 10
- MERGE ON CREATE ON MATCH with more than 12 properties seems to cause a subsequent binary format decode error HOT 2
- Problem with official example HOT 1
- Exposing ResponseError data type
- recommended resource-pool hangs when connect is not successful HOT 1
- ToJSON and FromJSON Instances to Node and Relationship Datatypes HOT 2
- Doesn't work for Neo4j version 5.7
- Fragile Pipes Syndrome HOT 2
- `Structure` is not exposed HOT 3
- `def` Cannot be found HOT 5
- Can't use Hasbolt with GrapheneDB HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hasbolt.