-
Notifications
You must be signed in to change notification settings - Fork 5
DELETE clause
Marijn van Wezel edited this page Dec 13, 2022
·
7 revisions
The DELETE
clause is used to delete nodes, relationships or paths. It accepts a list of structural values to be deleted.
Query::delete(Pattern|StructuralType|(Pattern|StructuralType)[] $structures, bool $detach = false): Query
Query::detachDelete(Pattern|StructuralType|(Pattern|StructuralType)[] $structures): Query
-
$structures
: The structures to delete. If aPattern
is given, it is automatically converted to a variable. -
$detach
: Whether toDETACH DELETE
.
-
setDetach(bool $detach = true): self
: Sets the clause toDETACH DELETE
. -
addStructure(Pattern|StructuralType ...$structures): self
: Add one or more structures to delete.
$unknown = node('Person')->withProperties([
'name' => 'UNKNOWN',
]);
$query = query()
->match($unknown)
->delete($unknown)
->build();
$this->assertStringMatchesFormat("MATCH (%s:Person {name: 'UNKNOWN'}) DELETE %s", $query);
$everything = node();
$query = query()
->match($everything)
->delete($everything)
->build();
$this->assertStringMatchesFormat("MATCH (%s) DELETE %s", $query);
$everything = node();
$query = query()
->match($everything)
->delete($everything, true)
->build();
$this->assertStringMatchesFormat("MATCH (%s) DETACH DELETE %s", $query);
$everything = node();
$query = query()
->match($everything)
->detachDelete($everything)
->build();
$this->assertStringMatchesFormat("MATCH (%s) DETACH DELETE %s", $query);
$persons = node('Person');
$animals = node('Animal');
$query = query()
->match([$persons, $animals])
->delete([$persons, $animals])
->build();
$this->assertStringMatchesFormat("MATCH (%s:Person), (%s:Animal) DELETE %s, %s", $query);