Parameterized Queries

neotypes leverages StringContext for interpolating query parameters. import neotypes.implicits._ adds 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" -> "John"))

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

c interpolator creates DeferredQueryBuilder which is an immutable representation of a cypher query. You can concatenate DeferredQueryBuilders with other DeferredQueryBuilders or Strings.

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})"