diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index 3f932ae..408a29b 100755 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -9,6 +9,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; +use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQueryBuilder; final class QueryBuilder { @@ -40,4 +41,8 @@ final class QueryBuilder { return new LinkQueryBuilder(); } + public static function Unlink(): UnlinkQueryBuilder + { + return new UnlinkQueryBuilder(); + } } diff --git a/src/QueryBuilder/QueryBuilderTrait.php b/src/QueryBuilder/QueryBuilderTrait.php index b3aea46..c6c24a7 100755 --- a/src/QueryBuilder/QueryBuilderTrait.php +++ b/src/QueryBuilder/QueryBuilderTrait.php @@ -13,6 +13,8 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; +use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQuery; +use Darksparrow\DeegraphInteractions\QueryBuilder\UnlinkQuery\UnlinkQueryBuilder; use Darksparrow\DeegraphInteractions\Utilities\RelativePath; use ReflectionClass; @@ -47,6 +49,7 @@ trait QueryBuilderTrait |PutQueryBuilder |ReferencesQueryBuilder |SelectQueryBuilder + |UnlinkQueryBuilder $target ): void { diff --git a/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php b/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php new file mode 100644 index 0000000..4fd10e2 --- /dev/null +++ b/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php @@ -0,0 +1,31 @@ +QueryString = $queryString; + } + public function __toString() + { + return $this->QueryString; + } + + public function RunQuery(DeegraphServer $server): UnlinkQueryResponse + { + $response = $server->RunRawRequest( + endpoint: "/api/v1/@query", + method: "POST", + body: $this->QueryString + ); + $temp = json_decode($response, true); + return new UnlinkQueryResponse($temp); + } +} diff --git a/src/QueryBuilder/UnlinkQuery/UnlinkQueryBuilder.php b/src/QueryBuilder/UnlinkQuery/UnlinkQueryBuilder.php new file mode 100644 index 0000000..aac417d --- /dev/null +++ b/src/QueryBuilder/UnlinkQuery/UnlinkQueryBuilder.php @@ -0,0 +1,65 @@ +PropertyName = $propertyName; + return $this; + } + public function From(): UnlinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "FROM"; + return $this; + } + public function Of(): UnlinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "OF"; + return $this; + } + public function RelativePath(string $relativePath): UnlinkQueryBuilder + { + $this->RelativePath = $relativePath; + return $this; + } + + + + + public function Build(): UnlinkQuery + { + self::ValidateValues(target: $this); + + $builder = "UNLINK " + . $this->PropertyName + . " " + . $this->Mode + . " " + . $this->RelativePath; + + return new UnlinkQuery(queryString: $builder); + } +} diff --git a/src/QueryBuilder/UnlinkQuery/UnlinkQueryResponse.php b/src/QueryBuilder/UnlinkQuery/UnlinkQueryResponse.php new file mode 100644 index 0000000..58ef9e3 --- /dev/null +++ b/src/QueryBuilder/UnlinkQuery/UnlinkQueryResponse.php @@ -0,0 +1,10 @@ +TestUUID}", + actual: QueryBuilder::Unlink() + ->PropertyName("test") + ->From() + ->RelativePath($this->TestUUID) + ->Build() + ); + } + public function test1() + { + self::assertEquals( + expected: "UNLINK test OF {$this->TestUUID}", + actual: QueryBuilder::Unlink() + ->PropertyName("test") + ->Of() + ->RelativePath($this->TestUUID) + ->Build() + ); + } + public function test2() + { + self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class); + self::assertEquals( + expected: "UNLINK test FROM {$this->TestUUID}", + actual: QueryBuilder::Unlink() + ->PropertyName("test") + ->From() + ->Of() + ->RelativePath($this->TestUUID) + ->Build() + ); + } +} \ No newline at end of file