From 7e3da11f720e7ae15e14e86eefb016b54be270a7 Mon Sep 17 00:00:00 2001 From: Cerys Date: Thu, 28 Nov 2024 16:03:41 +0000 Subject: [PATCH] code for the REFERENCES request --- examples/QueryExample_References.php | 21 +++++++++++ src/QueryBuilder/QueryBuilder.php | 5 +++ src/QueryBuilder/QueryBuilderTrait.php | 2 ++ .../ReferencesQuery/ReferencesQuery.php | 26 ++++++++++++++ .../ReferencesQueryBuilder.php | 35 +++++++++++++++++++ .../ReferencesQueryResponse.php | 13 +++++++ 6 files changed, 102 insertions(+) create mode 100644 examples/QueryExample_References.php create mode 100644 src/QueryBuilder/ReferencesQuery/ReferencesQuery.php create mode 100644 src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php create mode 100644 src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php diff --git a/examples/QueryExample_References.php b/examples/QueryExample_References.php new file mode 100644 index 0000000..389fef4 --- /dev/null +++ b/examples/QueryExample_References.php @@ -0,0 +1,21 @@ +RelativePath("{0b368d41-7c15-42c8-899c-2b178ae9d983}") + ->Build() + ->RunQuery(DeegraphConnection::DB()) +; + +echo "References\n"; +echo "=========\n"; + +foreach($result->Map as $key=>$value) +{ + echo str_pad($key, 20) . ": " . $value . "\n"; +} diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index a08b7b3..a3873af 100755 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -6,6 +6,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryB use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; +use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; final class QueryBuilder @@ -30,4 +31,8 @@ final class QueryBuilder { return new DirectoryQueryBuilder(); } + public static function References(): ReferencesQueryBuilder + { + return new ReferencesQueryBuilder(); + } } diff --git a/src/QueryBuilder/QueryBuilderTrait.php b/src/QueryBuilder/QueryBuilderTrait.php index e068db0..6993ce2 100755 --- a/src/QueryBuilder/QueryBuilderTrait.php +++ b/src/QueryBuilder/QueryBuilderTrait.php @@ -10,6 +10,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; +use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; use ReflectionClass; @@ -41,6 +42,7 @@ trait QueryBuilderTrait |InsertQueryBuilder |PermissionQueryBuilder |PutQueryBuilder + |ReferencesQueryBuilder |SelectQueryBuilder $target ): void diff --git a/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php b/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php new file mode 100644 index 0000000..11c44b7 --- /dev/null +++ b/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php @@ -0,0 +1,26 @@ +QueryString = $queryString; + } + + public function RunQuery(DeegraphServer $server): ReferencesQueryResponse + { + $response = $server->RunRawRequest( + endpoint: "/api/v1/@query", + method: "POST", + body: $this->QueryString + ); + $temp = json_decode($response, true); + return new ReferencesQueryResponse($temp); + } +} diff --git a/src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php b/src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php new file mode 100644 index 0000000..59af9b2 --- /dev/null +++ b/src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php @@ -0,0 +1,35 @@ +RelativePath = $relativePath; + return $this; + } + + public function Build(): ReferencesQuery + { + self::ValidateValues(target: $this); + + $builder = "REFERENCES " . $this->RelativePath; + + return new ReferencesQuery(queryString: $builder); + } +} \ No newline at end of file diff --git a/src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php b/src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php new file mode 100644 index 0000000..c67bae4 --- /dev/null +++ b/src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php @@ -0,0 +1,13 @@ +Map = $deegraphResponse["@map"]; + } +}