diff --git a/src/QueryBuilder/LinkQuery/LinkQuery.php b/src/QueryBuilder/LinkQuery/LinkQuery.php new file mode 100644 index 0000000..a86cc9d --- /dev/null +++ b/src/QueryBuilder/LinkQuery/LinkQuery.php @@ -0,0 +1,31 @@ +QueryString = $queryString; + } + public function __toString() + { + return $this->QueryString; + } + + public function RunQuery(DeegraphServer $server): LinkQueryResponse + { + $response = $server->RunRawRequest( + endpoint: "/api/v1/@query", + method: "POST", + body: $this->QueryString + ); + $temp = json_decode($response, true); + return new LinkQueryResponse($temp); + } +} \ No newline at end of file diff --git a/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php b/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php new file mode 100644 index 0000000..6301493 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php @@ -0,0 +1,106 @@ +RelativePath1 = $relativePath; + return $this; + } + public function LinkTo(string $relativePath): LinkQueryBuilder + { + self::EnsureNotSet($this->RelativePath2); + self::ValidateDeegraphPath(target: $relativePath); + $this->RelativePath2 = $relativePath; + $this->ToOrOf = "TO"; + return $this; + } + public function LinkOf(string $relativePath): LinkQueryBuilder + { + self::EnsureNotSet($this->RelativePath2); + self::ValidateDeegraphPath(target: $relativePath); + $this->RelativePath2 = $relativePath; + $this->ToOrOf = "OF"; + return $this; + } + + + + public function PropertyName(string $propertyName): LinkQueryBuilder + { + $this->PropertyName = $propertyName; + return $this; + } + + + + public function Overwrite(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "OVERWRITE"; + return $this; + } + public function Replace(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "REPLACE"; + return $this; + } + public function Force(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "FORCE"; + return $this; + } + + + + public function Build(): LinkQuery + { + self::ValidateValues(target: $this); + + $builder = "LINK " + . $this->RelativePath1 + . " " + . $this->ToOrOf + . " " + . $this->RelativePath2 + . " AS " + . $this->PropertyName; + + if($this->Mode != "") $builder .= " " . $this->Mode; + + return new LinkQuery(queryString: $builder); + } +} + diff --git a/src/QueryBuilder/LinkQuery/LinkQueryResponse.php b/src/QueryBuilder/LinkQuery/LinkQueryResponse.php new file mode 100644 index 0000000..81e5e87 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/LinkQueryResponse.php @@ -0,0 +1,10 @@ +TestUUID} TO {$this->TestUUID} AS test", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") + ->Build() + ); + } + public function test1() + { + self::assertEquals( + expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test OVERWRITE", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") + ->Overwrite() + ->Build() + ); + } + public function test2() + { + self::assertEquals( + expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test REPLACE", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") + ->Replace() + ->Build() + ); + } + public function test3() + { + self::assertEquals( + expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test FORCE", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") + ->Force() + ->Build() + ); + } + public function test4() + { + self::assertEquals( + expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkOf($this->TestUUID) + ->PropertyName("test") + ->Build() + ); + } + public function test5() + { + self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class); + self::assertEquals( + expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", + actual: QueryBuilder::Link() + ->LinkWhat($this->TestUUID) + ->LinkOf($this->TestUUID) + ->PropertyName("test") + ->Overwrite() + ->Replace() + ->Force() + ->Build() + ); + } +}