Parameterized Queries

neotypes leverages StringContext for interpolating query parameters. import neotypes.implicits.syntax.cypher._ adds the c interpolator into the implicit scope.

val name = "John"
val query = c"CREATE (a:Test {name: $name})"

assert(query.rawQuery == "CREATE (a:Test {name: $p1})")
assert(query.params == Map("p1" -> QueryParam("John")))

All parameters will be converted to neo4j supported types (please see Supported types).

The c interpolator creates a DeferredQueryBuilder which is an immutable representation of a cypher query. You can concatenate DeferredQueryBuilders with other DeferredQueryBuilders or Strings, to build complex queries.

val name = "John"
val born = 1980
val query = c"CREATE (a:Test {name: $name," + c"born: $born})"

val LABEL = "User"
val query2 = c"CREATE (a:" + LABEL + c"{name: $name})"