Create
This page describes how to add a CREATE clause with the Cypher®.Create class.
To add the CREATE clause, first create a valid pattern using the Pattern class:
const movie = new Cypher.Node();
const pattern = new Cypher.Pattern(movie, { labels: ["Movie"] });
const matchQuery = new Cypher.Create(pattern);
This generates the following CREATE clause:
CREATE (this:Movie)
Properties can be passed to the Pattern to create the node with its properties:
const movie = new Cypher.Node();
const pattern = new Cypher.Pattern(movie, { labels: ["Movie"], properties: { title: "The Matrix" } });
const matchQuery = new Cypher.Create(pattern);
This generates the following CREATE clause:
CREATE (this:Movie {title: "The Matrix"})
Relationships
Relationships can be used in a match clause by creating the relevant Pattern:
const actedInPattern = new Cypher.Pattern(movieNode, { labels: ["Movie"] })
.related({ type: "ACTED_IN" })
.to(personNode, { labels: ["Person"] });
const create = new Cypher.Create(actedInPattern)
CREATE (this1:`Person`)-[this0:ACTED_IN]->(this2:`Movie`)
Update properties
Add the SET and REMOVE clauses with the methods .set and .remove respectively.
.set takes one or more tuples, each consisting of a property to update and a new value:
const createQuery = new Cypher.Create(new Cypher.Pattern(movie, { labels: ["Movie"] })).set([
movie.property("title"),
new Cypher.Param("The Matrix"),
]);
CREATE (this0:Movie)
SET this0.title = $param0
Multiple properties can be updated by passing multiple tuples.
.remove takes the properties to remove:
const createQuery = new Cypher.Create(new Cypher.Pattern(movie, { labels: ["Movie"] })).remove(
movie.property("title"),
movie.property("year")
);
CREATE (this0:Movie)
REMOVE this0.title, this0.year