View Source RedisGraph.Query (ex_redisgraph v0.1.0)
Query module provides functions to build the cypther query for RedisGraph database.
The module exposes functions that represent
entities (Node/Relationship) and [Cypher clauses]
(https://redis.io/docs/stack/graph/cypher_support/#clauses)
(MATCH/WHERE/RETURN etc.) through which client can build
the desired query and pass it to RedisGraph.query/3 to
interact with the database. Query structure holds the context,
that contains data necessary when building the actual query.
The context shouldn't be altered by the client directly,
instead only public functions from this module should be,
which would internally change it.
The RedisGraph.Query supports the following Cypher clauses through functions:
- CREATE:
create/1 - MATCH:
match/1 - OPTIONALMATCH
:optional_match/1- MERGE:merge/1- DELETE:delete/2- WHERE:where/5,where_not/5,or_where/5,and_where/5,xor_where/5,or_not_where/5,and_not_where/5,xor_not_where/5- ORDERBY:order_by/3 - SET:
set/4,set_property/5 - ONMATCH SET
:on_match_set/4,on_match_set_property/5- ONCREATE SET:on_create_set/4,on_create_set_property/5 - WITH:
with/3,with_property/4,with_function/4,with_function_and_property/5 - LIMIT:
limit/2 SKIP:skip/2RETURN:return/3,return_property/4,return_function/4,return_function_and_property/5RETURN DISTINCT:return_distinct/3,return_distinct_property/4,return_distinct_function/4,return_distinct_function_and_property/5
Node entity is supported through functions: node/3, node/4
Relatioshipentity is supported through functions: relationship_from_to/3, relationship_from_to/4, relationship_to_from/3, relationship_to_from/4
After building the query, you will end up with either {:ok, query_message} or {:error, error_message}.
The workflow of using the RedisGraphQuery module is the following:
- create anew query using
new/0 - populate the query through
match/1,node/3,return/3etc. - receive the query string by building it through
build_query/1
examples
Examples
# Creating a valid query
{:ok, query} =
Query.new()
|> Query.match()
|> Query.node(:n, ["Person"], %{age: 30, name: "John Doe", works: true})
|> Query.relationship_from_to(:r, "TRAVELS_TO", %{purpose: "pleasure"})
|> Query.node(:m, ["Place"], %{name: "Japan"})
|> Query.return(:n)
|> Query.return_property(:n, "age", :Age)
|> Query.return(:m)
|> Query.build_query()
# query will hold
# "MATCH "MATCH (n:Person {age: 30, name: 'John Doe', works: true})-[r:TRAVELS_TO {purpose: 'pleasure'}]->(m:Place {name: 'Japan'}) RETURN n, n.age AS Age, m"
# Creating an invalid query
{:error, error} =
Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 30, name: "John Doe", works: true}) |> Query.relationship_from_to(:r, "TRAVELS_TO", %{purpose: "pleasure"}) |> Query.node(:m, ["Place"], %{name: "Japan"}) |> Query.build_query()
# error will hold
# "In case you provide MATCH, OPTIONAL MATCH - then RETURN, RETURN DISCTINCT or DELETE also has to be provided. E.g. new() |> match |> node(:n) |> return(:n)"You will specify the node through node() and relationship through either relationship_from_to() or relationship_to_from().
{:ok, query} = Query.new()
|> Query.create()
|> Query.node(:n, ["Person"])
|> Query.relationship_from_to(:r, "TRAVELS_TO")
|> Query.node(:m, ["City"])
|> Query.relationship_from_to(:t, "IN")
|> Query.node(:b, ["Country"])
|> Query.relationship_to_from(:y, "HAS")
|> Query.node(:v, ["Emperor"])
|> Query.build_query()
# query would hold
# "CREATE (n:Person)-[r:TRAVELS_TO]->(m:City)-[t:IN]->(b:Country)<-[y:HAS]-(v:Emperor)"
Link to this section Summary
Functions
Add WHERE ... AND NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add WHERE ... AND ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Function used to build the query string from the Redisgraph.Query context.
Function receives the context as argument and returns either {:ok, query_string}
or {:error, error_message}
Add CREATE clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
Add DELETE clause into the context and receive the updated context.
Provide the context and alias (as atom) of the entity you want to delete.
Add LIMIT clause into the context and receive the updated context.
Provide the context and number of rows you want to limit to.
Add MATCH clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
Add MERGE clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
Used to initialize the RedisGraph.Query structure and create the query.
Funciton returns the query context, whose contents should be updated using
subsequent functions in this module (e.g. match/1, return/3) and not manipulated directly.
Add a Node to a clause and receive the updated context.
Provide the context, alias (as atom) of the node and option as a list of labels (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add a Node to a clause and receive the updated context.
Provide the context, alias (as atom) of the node you want to add, a list of labels (as Strings) and a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add ON CREATE SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
Add ON CREATE SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
Add ON MATCH SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
Add ON MATCH SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
Add OPTIONAL MATCH clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
Add WHERE ... OR NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add WHERE ... OR ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add ORDER BY clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, a property
for the given entity on which you want to order and a asc boolean
(if set to true, the order is ASC and if false, order is DESC).
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and an option as
of relation type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add, a type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and a type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and an option as
of relation type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
Add RETURN clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to return
and an atom as that would hold the new name of the result.
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to return
and an atom as that would hold the new name of the result.
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
Add RETURN clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
Add RETURN clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
Add RETURN clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
Add SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
Add SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
Add SKIP clause into the context and receive the updated context.
Provide the context and number of rows you want to skip.
Add WHERE clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add WHERE NOT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add WITH clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to chain
and an atom as that would hold the new name of the result.
Add WITH clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
Add WITH clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
Add WITH clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
Add WHERE ... XOR NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Add WHERE ... XOR ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Link to this section Types
@opaque t()
Link to this section Functions
@spec and_not_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... AND NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
and_not_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.and_not_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 AND NOT n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.and_not_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
@spec and_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... AND ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
and_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.and_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 AND n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.and_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
Function used to build the query string from the Redisgraph.Query context.
Function receives the context as argument and returns either {:ok, query_string}
or {:error, error_message}
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n:Person {age: 5}) RETURN n"If the client uses the function incorrectly, the error will be returned.
example-1
Example
{:error, query} = Query.match(%{}) |> Query.node(:n, ["Person"], %{age: 5}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "Please instantiate the query first with new(). Istead have e.g. new() |> match |> node(:n) |> return(:n) |> build_query()"
Add CREATE clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
After create/1 provide the entities which you want to match using
node/2, relationship_from_to, relationship_to_from/2 functions.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.create() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "CREATE (n:Person {age: 30, name: 'John'}) RETURN n"
Add DELETE clause into the context and receive the updated context.
Provide the context and alias (as atom) of the entity you want to delete.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.delete(:n) |> Query.build_query()
# query will hold
# "MATCH (n:Person {age: 30, name: 'John'}) DELETE n"If provided entity alias is was not mentioned before, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.create() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.delete(:m) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> order_by_property(:n, "age") |> ..."
@spec limit(t(), non_neg_integer()) :: t()
Add LIMIT clause into the context and receive the updated context.
Provide the context and number of rows you want to limit to.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.limit(10)|> Query.build_query()
# query will hold
# "MATCH (n) RETURN n LIMIT 10"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.limit("test")|> Query.build_query()
# error will hold
# "Wrong number parameter was probided, only non negatibe integers supported. E.g. new() |> match() |> node(:n) |> return(:n) |> limit(10)|> build_query()"
Add MATCH clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
After match/1 provide the entities which you want to match using
node/2, relationship_from_to/2, relationship_to_from/2 functions.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n:Person {age: 30, name: 'John'}) RETURN n"
Add MERGE clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
After merge/1 provide the entities which you want to match using
node/2, relationship_from_to/2, relationship_to_from/2 functions.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.merge() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MERGE (n:Person {age: 30, name: 'John'}) RETURN n"
@spec new() :: t()
Used to initialize the RedisGraph.Query structure and create the query.
Funciton returns the query context, whose contents should be updated using
subsequent functions in this module (e.g. match/1, return/3) and not manipulated directly.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) RETURN n"
Add a Node to a clause and receive the updated context.
Provide the context, alias (as atom) of the node and option as a list of labels (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n:Person) RETURN n"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n {age: 30, name: 'John'}) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.node(:n, ["Person"]) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH or OPTIONAL MATCH or CREATE or MERGE clause has to be provided first before using node(). E.g. new() |> match() |> node(:n) |> ..."
Add a Node to a clause and receive the updated context.
Provide the context, alias (as atom) of the node you want to add, a list of labels (as Strings) and a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n:Person {age: 30, name: 'John'}) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH or OPTIONAL MATCH or CREATE or MERGE clause has to be provided first before using node(). E.g. new() |> match() |> node(:n) |> ..."
Add ON CREATE SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
Should only be used when MERGE clause is provided first.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.merge() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_create_set(:n, %{name: "Michael"}, "+=") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MERGE (n:Person {age: 5}) ON CREATE SET n += {name: 'Michael'} RETURN n"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = uery.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.on_create_set(:m, %{}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MERGE clause has to be provided first before using ON CREATE SET. E.g. new() |> merge() |> node(:n) |> node(:m) |> on_create_set(:n, "m") |> return(:n) |> ..."
on_create_set_property(context, alias, property, value, operator \\ "=")
View SourceAdd ON CREATE SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
Should only be used when MERGE clause is provided first.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.merge() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_create_set_property(:n, "age", 50) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MERGE (n:Person {age: 5}) ON CREATE SET n.age = 50 RETURN n"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_create_set_property(:n, "age", 50) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MERGE clause has to be provided first before using ON CREATE SET. E.g. new() |> merge() |> node(:n) |> node(:m) |> on_create_set(:n, "m") |> return(:n) |> ..."
Add ON MATCH SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
Should only be used when MERGE clause is provided first.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.merge() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_match_set(:n, %{name: "Michael"}, "+=") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MERGE (n:Person {age: 5}) ON MATCH SET n += {name: 'Michael'} RETURN n"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = uery.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.on_match_set(:m, %{}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MERGE clause has to be provided first before using ON MATCH SET. E.g. new() |> merge() |> node(:n) |> node(:m) |> on_create_set(:n, "m") |> return(:n) |> ..."
on_match_set_property(context, alias, property, value, operator \\ "=")
View SourceAdd ON MATCH SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
Should only be used when MERGE clause is provided first.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.merge() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_match_set_property(:n, "age", 50) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MERGE (n:Person {age: 5}) ON MATCH SET n.age = 50 RETURN n"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"], %{age: 5}) |> Query.on_match_set_property(:n, "age", 50) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MERGE clause has to be provided first before using ON MATCH SET. E.g. new() |> merge() |> node(:n) |> node(:m) |> on_create_set(:n, "m") |> return(:n) |> ..."
Add OPTIONAL MATCH clause into the context and receive the updated context.
Receives the context which is provided from new/0 function.
After optional_match/1 provide the entities which you want to match using
node/2, relationship_from_to/2, relationship_to_from/2 functions.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.optional_match() |> Query.node(:n, ["Person"], %{age: 30, name: "John"}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "OPTIONAL MATCH (n:Person {age: 30, name: 'John'}) RETURN n"
@spec or_not_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... OR NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
or_not_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.or_not_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 OR NOT n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.or_not_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
@spec or_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... OR ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
or_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.or_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 OR n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.or_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
Add ORDER BY clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, a property
for the given entity on which you want to order and a asc boolean
(if set to true, the order is ASC and if false, order is DESC).
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.order_by(:n, "age") |> Query.build_query()
# query will hold
# "MATCH (n) RETURN n ORDER BY n.age ASC"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.order_by(:n, "") |> Query.build_query()
# error will hold
# "Provide property name. E.g. new() |> match() |> node(:n) |> order_by(:n, "age") |> return(:n) |> ..."
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and an option as
of relation type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
relationship_from_to() will convert to (:from_node)-[:rel]->(:to_node)
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_from_to(:r, "KNOWS") |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)-[r:KNOWS]->(m) RETURN n"
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_from_to(:r, %{duration: 100}) |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)-[r {duration: 100}]->(m) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_from_to(:r, %{duration: 100}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH clause cannot end with a Relationship, add a Node at the end. E.g. new() |> match() |> node(:n) |> relationship_from_to(:r) |> node(:m) |> ..."
relationship_from_to(context, alias, type \\ "", properties \\ %{})
View SourceAdd a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add, a type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
relationship_from_to() will convert to (:from_node)-[:rel]->(:to_node)
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_from_to(:r, "TRAVELS", %{duration: 100}) |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)-[r:TRAVELS {duration: 100}]->(m) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_from_to(:r, "TRAVELS", %{duration: 100}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH clause cannot end with a Relationship, add a Node at the end. E.g. new() |> match() |> node(:n) |> relationship_from_to(:r) |> node(:m) |> ..."
Add a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and a type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
relationship_to_from() will convert to (:to_node)<-[:rel]-(:from_node)
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_to_from(:r, "KNOWS") |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)<-[r:KNOWS]-(m) RETURN n"
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_to_from(:r, %{duration: 100}) |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)<-[r {duration: 100}]-(m) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_to_from(:r, %{duration: 100}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH clause cannot end with a Relationship, add a Node at the end. E.g. new() |> match() |> node(:n) |> relationship_from_to(:r) |> node(:m) |> ..."
relationship_to_from(context, alias, type \\ "", properties \\ %{})
View SourceAdd a Relationship to a clause and receive the updated context.
Provide the context, alias (as atom) of the relationship you want to add and an option as
of relation type (as Strings) or a map of properties.
The function can be used along with MATCH, OPTIONAL MATCH, CREATE, MERGE clauses.
relationship_to_from() will convert to (:to_node)<-[:rel]-(:from_node)
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_to_from(:r, "TRAVELS", %{duration: 100}) |> Query.node(:m) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n)<-[r:TRAVELS {duration: 100}]-(m) RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match |> Query.node(:n) |> Query.relationship_to_from(:r, "TRAVELS", %{duration: 100}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "MATCH clause cannot end with a Relationship, add a Node at the end. E.g. new() |> match() |> node(:n) |> relationship_from_to(:r) |> node(:m) |> ..."
Add RETURN clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to return
and an atom as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return(:n, :Person) |> Query.build_query()
# query will hold
# "MATCH (n:Person) RETURN n AS Person"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.node(:m, ["Dog"]) |> Query.return(:n) |> Query.return(:m) |> Query.build_query()
# query will hold
# "MATCH (n:Person),(m:Dog) RETURN n, m"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return(:m) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> order_by_property(:n, "age") |> ..."
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to return
and an atom as that would hold the new name of the result.
Look at return() for examples
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
Look at return_function() for examples
return_distinct_function_and_property(context, function, alias, property, as \\ nil)
View Source@spec return_distinct_function_and_property( t(), String.t(), atom(), String.t(), atom() | nil ) :: t()
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
Look at return_function_and_property() for examples
Add RETURN DISTINCT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
Look at return_property() for examples
Add RETURN clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return_property(:n,"age", :Person) |> Query.build_query()
# query will hold
# "MATCH (n) RETURN n, labels(n) AS Labels"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.return_function("labels", :n, :Labels) |> Query.build_query()
# query will hold
# "MATCH (n) RETURN n, labels(n) AS Labels"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.return_function("", :n, :Labels) |> Query.build_query()
# error will hold
# "Provide function name. E.g. new() |> match() |> node(:n) |> return_function("toUpper", :n) |> ..."
return_function_and_property(context, function, alias, property, as \\ nil)
View SourceAdd RETURN clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.return_function_and_property("toUpper", :n, "name", :Name) |> Query.build_query()
# query will hold
# "MATCH (n) RETURN n, toUpper(n.name) AS Name"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} =Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.return_function_and_property("toUpper", :n, "name", "Name") |> Query.build_query()
# error will hold
# ""Provided as attribute: Name needs to be an atom. E.g. Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n, :Node) |> Query.build_query()"
Add RETURN clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return_property(:n,"age", :Person) |> Query.build_query()
# query will hold
# "MATCH (n:Person) RETURN n.age AS Person"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return(:n) |> Query.return_property(:n, "age") |> Query.build_query()
# query will hold
# "MATCH (n:Person) RETURN n, n.age"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n, ["Person"]) |> Query.return_property(:m, "") |> Query.build_query()
# error will hold
# "Provide property name. E.g. new() |> match() |> node(:n) |> return_property(:n, "age") |> ..."
Add SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, new value
you want to set and operator.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.set(:n, %{}) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n {age: 5, name: 'John'}) SET n = {} RETURN n"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.set(:n, %{works: false}, "+=") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n {age: 5, name: 'John'}) SET n += {works: false} RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = uery.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.set(:m, %{}) |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> order_by_property(:n, "age") |> ..."
Add SET clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the
property, new value you want to set and operator.
value arbument can be of the following type:
- String
- number
- boolean
- nil
- list
- map
operator can be:
- "=" (default) -- for assignment
- "+=" -- for update
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.set_property(:n, "age", 25) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n {age: 5, name: 'John'}) SET n.age = 25 RETURN n"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = uery.new() |> Query.match() |> Query.node(:n, %{age: 5, name: "John"}) |> Query.set_property(:m, "age", 25) |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> order_by_property(:n, "age") |> ..."
@spec skip(t(), non_neg_integer()) :: t()
Add SKIP clause into the context and receive the updated context.
Provide the context and number of rows you want to skip.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.skip(10)|> Query.build_query()
# query will hold
# "MATCH (n) RETURN n SKIP 10"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.return(:n) |> Query.skip("test")|> Query.build_query()
# error will hold
# "Wrong number parameter was probided, only non negatibe integers supported. E.g. new() |> match() |> node(:n) |> return(:n) |> skip(10)|> build_query()"
@spec where( t(), atom(), String.t(), accepted_operator_in_where_clause(), accepted_value() ) :: t()
Add WHERE clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Supported values(on the left) and operators (on the left):
- type
String-> provide:equals, :not_equal, :bigger, :bigger_or_equal, :smaller, :smaller_or_equal, :starts_with, :ends_with, :contains - type
number->:equals, :not_equal, :bigger, :bigger_or_equal, :smaller, :smaller_or_equal - type
boolean->:equals - type
nil->:is, :is_not - type
list->:in
The operator will be converted to:
- :equals -> "="
- :not_equal -> "<>"
- :bigger -> ">"
- :bigger_or_equal -> ">="
- :smaller -> "<"
- :smaller_or_equal -> "<="
- :starts_with -> "STARTS WITH"
- :ends_with -> "ENDS WITH"
- :contains -> "CONTAINS"
- :in -> "IN"
- :is -> "IS"
- :is_not -> "IS NOT
where() can be used just once. If you want to have several conditions in WHERE clause, use
where() along with other functions, such as or_where()/or_not_where() etc.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :test, 5) |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
@spec where_not( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE NOT clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
where_not() can be used just once. If you want to have several conditions in WHERE clause, use
where_not() along with other functions, such as or_where()/or_not_where() etc.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where_not(:n, "age", :bigger, 5) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE NOT n.age > 5 RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where_not(:n, "age", :test, 5) |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
Add WITH clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to chain
and an atom as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with(:n, :Node) |> Query.return(:Node) |> Query.build_query()
# query will hold
# "MATCH (n) WITH n AS Node RETURN Node"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with(:m, :Node) |> Query.return(:Node) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> with(:n, :Node) |> |> return(:n) ..."
Add WITH clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity you want to return and and atom
as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_function("labels", :n, :Labels) |> Query.return(:Labels) |> Query.build_query()
# query will hold
# "MATCH (n) WITH labels(n) AS Labels RETURN Labels"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_function("labels", :m, :Labels) |> Query.return(:Labels) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> with(:n, :Node) |> |> return(:n) ..."
with_function_and_property(context, function, alias, property, as \\ nil)
View Source@spec with_function_and_property( t(), String.t() | nil, atom(), String.t() | nil, atom() | nil ) :: t()
Add WITH clause into the context and receive the updated context.
Provide the context, name of the function which should be called,
alias (as atom) of the entity, name of the property you want to return
and and atom as that would hold the new name of the result.
Instead of entity alias, :* atom can be provided.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_function_and_property("toUpper", :n, "Name", :Name) |> Query.return(:Name) |> Query.build_query()
# query will hold
# "MATCH (n) WITH toUpper(n.Name) AS Name RETURN Name"
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with(:*) |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WITH * RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_function_and_property("toUpper", :m, "Name", :Name) |> Query.return(:Name) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> with(:n, :Node) |> |> return(:n) ..."
Add WITH clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity, name of the property
you want to return and an atom as that would hold the new name of the result.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_property(:n,"age", :Age) |> Query.return(:Age) |> Query.build_query()
# query will hold
# "MATCH (n) WITH n.age AS Age RETURN Age"
If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.with_property(:m,"age", :Age) |> Query.return(:Node) |> Query.build_query()
# error will hold
# "Provided alias: :m was not mentioned before. Pass the alias first: e.g. new() |> match() |> node(:n) |> with(:n, :Node) |> |> return(:n) ..."
@spec xor_not_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... XOR NOT ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
xor_not_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.xor_not_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 XOR NOT n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.xor_not_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."
@spec xor_where( t(), atom(), String.t(), accepted_operator_in_where_clause(), String.t() | number() | boolean() | list() | nil ) :: t()
Add WHERE ... XOR ... clause into the context and receive the updated context.
Provide the context, alias (as atom) of the entity you want to filter on,
a property for the given entity, a single operator (as atom) and a value.
Check where() to see the supported values and operators.
xor_where() is used when you want to have several logical conditions is WHERE clause,
so where()/where_not() already needs to present as well.
example
Example
alias RedisGraph.{Query}
{:ok, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.xor_where(:n, "name", :contains, "A") |> Query.return(:n) |> Query.build_query()
# query will hold
# "MATCH (n) WHERE n.age > 5 XOR n.name CONTAINS 'A' RETURN n"If the client uses the function incorrectly, the error will be persisted and returned when the client will try to build the query.
example-1
Example
{:error, query} = Query.new() |> Query.match() |> Query.node(:n) |> Query.where(:n, "age", :bigger, 5) |> Query.xor_where(:n, "name", :test, "A") |> Query.return(:n) |> Query.build_query()
# error will hold
# "Provided value: 5 or/and operator: :test in the WHERE clause is not supported."