EctoNeo4j v0.6.4 Ecto.Adapters.Neo4j.Cql.Node View Source

Cypher query builder for Node

Link to this section Summary

Functions

Handle creation of unique constraints. Note that uniqueness on multiple properties is only available in Enterprise Edition

Builds a cypher for deleting a cosntraint or an index from the database. Required a constraint cql similar to the one provided by CALL db.constraints()

Handle creation of non unique indexes.

Handle creation of non null constraints.

Returns cypher query to delete a node.

Returns cypher query to delete all database data.

Returns cypher query to delete all given nodes. This operation shoudl be performed as a btach for performance reason.

Handle deletion of unique constraints. Note that uniqueness on multiple properties is only available in Enterprise Edition

Builds a cypher for deleting a cosntraint or an index from the database. Required a constraint cql similar to the one provided by CALL db.constraints()

Handle deletion of non unique indexes.

Handle deletion of non null constraints.

Returns cypher query and params to insert a new node.

Builds a cypher query for listing all the constraints for a specific node.

Builds a cypher query for listing all the indexes for a specific node.

Build a query to relabel a node.

Bulds a query to rename a property

Returns cypher query to update node data.

Link to this section Functions

Link to this function

create_constraint(node_label, columns) View Source
create_constraint(String.t(), [String.t()]) :: String.t()

Handle creation of unique constraints. Note that uniqueness on multiple properties is only available in Enterprise Edition

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.create_constraint("Post", [:title])
"CREATE CONSTRAINT ON (n:Post) ASSERT n.title IS UNIQUE"
iex> Ecto.Adapters.Neo4j.Cql.Node.create_constraint("Post", [:title, :author])
"CREATE CONSTRAINT ON (n:Post) ASSERT (n.title, n.author) IS NODE KEY"
Link to this function

create_constraint_index_from_cql(cql) View Source
create_constraint_index_from_cql(String.t()) :: String.t()

Builds a cypher for deleting a cosntraint or an index from the database. Required a constraint cql similar to the one provided by CALL db.constraints()

Example

iex> constraint_cql = "CONSTRAINT ON ( posts:posts ) ASSERT posts.uuid IS UNIQUE"
iex> Ecto.Adapters.Neo4j.Cql.Node.create_constraint_index_from_cql(constraint_cql)
"CREATE CONSTRAINT ON ( posts:posts ) ASSERT posts.uuid IS UNIQUE"
iex> index_cql = "INDEX ON :posts(nodeId)"
iex> Ecto.Adapters.Neo4j.Cql.Node.create_constraint_index_from_cql(index_cql)
"CREATE INDEX ON :posts(nodeId)"
Link to this function

create_index(node_label, columns) View Source
create_index(String.t(), [String.t()]) :: String.t()

Handle creation of non unique indexes.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.create_index("Post", [:title])
"CREATE INDEX ON :Post(title)"
iex> Ecto.Adapters.Neo4j.Cql.Node.create_index("Post", [:title, :author])
"CREATE INDEX ON :Post(title, author)"
Link to this function

create_non_null_constraint(node_label, column) View Source
create_non_null_constraint(String.t(), atom()) :: String.t()

Handle creation of non null constraints.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.create_non_null_constraint("Post", :title)
"CREATE CONSTRAINT ON (n:Post) ASSERT exists(n.title)"
Link to this function

delete(node_label, filters) View Source
delete(String.t(), map()) :: {String.t(), map()}

Returns cypher query to delete a node.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.delete("Post", %{uuid: "a-valid-uuid"})
{"MATCH
  (n:Post)
WHERE
  n.uuid = {uuid}
DETACH DELETE
  n
RETURN
  n
", %{uuid: "a-valid-uuid"}}
Link to this function

delete_all() View Source
delete_all() :: String.t()

Returns cypher query to delete all database data.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.delete_all()
"MATCH
  (n)
DETACH DELETE
  n
"
Link to this function

delete_nodes(node_label) View Source
delete_nodes(String.t()) :: String.t()

Returns cypher query to delete all given nodes. This operation shoudl be performed as a btach for performance reason.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.delete_nodes("Post")
"MATCH
  (n:Post)
WITH
  n AS n
LIMIT
  {limit}
DETACH DELETE
  n
RETURN
  COUNT(n) AS nb_touched_nodes
"
Link to this function

drop_constraint(node_label, columns) View Source
drop_constraint(String.t(), [String.t()]) :: String.t()

Handle deletion of unique constraints. Note that uniqueness on multiple properties is only available in Enterprise Edition

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.drop_constraint("Post", [:title])
"DROP CONSTRAINT ON (n:Post) ASSERT n.title IS UNIQUE"
iex> Ecto.Adapters.Neo4j.Cql.Node.drop_constraint("Post", [:title, :author])
"DROP CONSTRAINT ON (n:Post) ASSERT (n.title, n.author) IS NODE KEY"
Link to this function

drop_constraint_index_from_cql(cql) View Source
drop_constraint_index_from_cql(String.t()) :: String.t()

Builds a cypher for deleting a cosntraint or an index from the database. Required a constraint cql similar to the one provided by CALL db.constraints()

Example

iex> constraint_cql = "CONSTRAINT ON ( posts:posts ) ASSERT posts.uuid IS UNIQUE"
iex> Ecto.Adapters.Neo4j.Cql.Node.drop_constraint_index_from_cql(constraint_cql)
"DROP CONSTRAINT ON ( posts:posts ) ASSERT posts.uuid IS UNIQUE"
iex> index_cql = "INDEX ON :posts(nodeId)"
iex> Ecto.Adapters.Neo4j.Cql.Node.drop_constraint_index_from_cql(index_cql)
"DROP INDEX ON :posts(nodeId)"
Link to this function

drop_index(node_label, columns) View Source
drop_index(String.t(), [String.t()]) :: String.t()

Handle deletion of non unique indexes.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.drop_index("Post", [:title])
"DROP INDEX ON :Post(title)"
iex> Ecto.Adapters.Neo4j.Cql.Node.drop_index("Post", [:title, :author])
"DROP INDEX ON :Post(title, author)"
Link to this function

drop_non_null_constraint(node_label, column) View Source
drop_non_null_constraint(String.t(), atom()) :: String.t()

Handle deletion of non null constraints.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.drop_non_null_constraint("Post", :title)
"DROP CONSTRAINT ON (n:Post) ASSERT exists(n.title)"
Link to this function

insert(node_label, data, primary_keys, return \\ []) View Source

Returns cypher query and params to insert a new node.

Example

iex> data = %{title: "New title", uuid: "a-valid-uuid"}
iex> Ecto.Adapters.Neo4j.Cql.Node.insert("Post", data, [:uuid])
{"MERGE
  (n:Post {uuid: {uuid}})
ON CREATE SET
  n.title = {title},  \nn.uuid = {uuid}\n
RETURN
  n
", %{title: "New title", uuid: "a-valid-uuid"}}

# With returning fields specified
iex> data = %{title: "New title", uuid: "a-valid-uuid"}
iex> Ecto.Adapters.Neo4j.Cql.Node.insert("Post", data, [:uuid], [:uuid])
{"MERGE
  (n:Post {uuid: {uuid}})
ON CREATE SET
  n.title = {title},  \nn.uuid = {uuid}\n
RETURN
  n.uuid AS uuid
", %{title: "New title", uuid: "a-valid-uuid"}}
Link to this function

list_all_constraints(node_label, property \\ nil) View Source
list_all_constraints(String.t(), atom()) :: String.t()

Builds a cypher query for listing all the constraints for a specific node.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.list_all_constraints("Post")
"CALL db.constraints()
YIELD description
WHERE description CONTAINS \":Post\" \nRETURN description
"
iex> Ecto.Adapters.Neo4j.Cql.Node.list_all_constraints("Post", :title)
"CALL db.constraints()
YIELD description
WHERE description CONTAINS \":Post\" AND description CONTAINS '.title'
RETURN description
"
Link to this function

list_all_indexes(node_label, property \\ nil) View Source
list_all_indexes(String.t(), nil | atom()) :: String.t()

Builds a cypher query for listing all the indexes for a specific node.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.list_all_indexes("Post")
"CALL db.indexes()
YIELD description
WHERE description CONTAINS \":Post\" \nRETURN description
"
iex> Ecto.Adapters.Neo4j.Cql.Node.list_all_indexes("Post", :title)
"CALL db.indexes()
YIELD description
WHERE description CONTAINS \":Post\" AND description CONTAINS 'title'
RETURN description
"
Link to this function

relabel(old_label, new_label) View Source
relabel(String.t(), String.t()) :: String.t()

Build a query to relabel a node.

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.relabel("Post", "NewPost")
"MATCH
  (n:Post)
WITH
  n AS n
LIMIT
  {limit}
SET
  n:NewPost
REMOVE
  n:Post
RETURN
  COUNT(n) AS nb_touched_nodes
"
Link to this function

rename_property(node_label, old_name, new_name) View Source
rename_property(String.t(), String.t(), String.t()) :: String.t()

Bulds a query to rename a property

Example

iex> Ecto.Adapters.Neo4j.Cql.Node.rename_property("Post", "titttle", "title")
"MATCH
  (n:Post)
WITH
  n AS n
SKIP
  {skip}
LIMIT
  {limit}
SET
  n.title = n.titttle
REMOVE
  n.titttle
RETURN
  COUNT(n) AS nb_touched_nodes
"
Link to this function

update(node_label, data, filters \\ %{}) View Source
update(String.t(), map(), map()) :: {String.t(), map()}

Returns cypher query to update node data.

Example

iex> data = %{title: "New title"}
iex> filters = %{id: 5}
iex> Ecto.Adapters.Neo4j.Cql.Node.update("Post", data, filters)
{"MATCH
  (n:Post)
WHERE
  n.id = {f_id}
SET
  n.title = {title}
RETURN
  n
", %{f_id: 5, title: "New title"}}