Skip to content

Commit

Permalink
Minor code changes and add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvanwezel committed Dec 15, 2022
1 parent 27633fa commit 7f0cb00
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 136 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ To construct a query to find all of Tom Hanks' co-actors, you can use the
following code:

```php
$tom = Query::node("Person")->withProperties(["name" => "Tom Hanks"]);
$coActors = Query::node();
use function WikibaseSolutions\CypherDSL\node;
use function WikibaseSolutions\CypherDSL\query;

$statement = Query::new()
$tom = node("Person")->withProperties(["name" => "Tom Hanks"]);
$coActors = node();

$statement = query()
->match($tom->relationshipTo(Query::node(), "ACTED_IN")->relationshipFrom($coActors, "ACTED_IN"))
->returning($coActors->property("name"))
->build();

$this->assertStringMatchesFormat("MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->()<-[:ACTED_IN]-(%s) RETURN %s.name", $statement);
```
2 changes: 1 addition & 1 deletion src/Clauses/ReturnClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function addColumn(...$columns): self
}

/**
* Sets this query to only retrieve unique rows.
* Sets this query to only return unique rows.
*
* @return $this
*
Expand Down
29 changes: 0 additions & 29 deletions src/Clauses/UnionClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,6 @@ final class UnionClause extends Clause
*/
private bool $all = false;

/**
* Combines two queries with a union.
*
* @param Query $left the query preceding the union clause
* @param Query $right the query after the union clause
* @param bool $all Whether the union should include all results or remove the duplicates instead.
*
* TODO: Move this function somewhere else.
*/
public static function union(Query $left, Query $right, bool $all = false): Query
{
$tbr = Query::new();

foreach ($left->getClauses() as $clause) {
$tbr->addClause($clause);
}

$unionClause = new self();
$unionClause->setAll($all);

$tbr->addClause($unionClause);

foreach ($right->getClauses() as $clause) {
$tbr->addClause($clause);
}

return $tbr;
}

/**
* Sets that the union should include all results, instead of removing duplicates.
*
Expand Down
Loading

0 comments on commit 7f0cb00

Please sign in to comment.