diff --git a/src/QueryBuilder/SelectQuery/SelectQuery.php b/src/QueryBuilder/SelectQuery/SelectQuery.php index b8803a4..7914d13 100644 --- a/src/QueryBuilder/SelectQuery/SelectQuery.php +++ b/src/QueryBuilder/SelectQuery/SelectQuery.php @@ -12,8 +12,12 @@ class SelectQuery { $this->QueryString = $queryString; } + public function __toString() + { + return $this->QueryString; + } - public function RunQuery(DeegraphServer $server): array + public function RunQuery(DeegraphServer $server): SelectQueryResponse { $response = $server->RunRawRequest( endpoint: "/api/v1/@query", @@ -21,6 +25,6 @@ class SelectQuery body: $this->QueryString ); $temp = json_decode($response, true); - return $temp; + return new SelectQueryResponse($temp); } } diff --git a/src/QueryBuilder/SelectQuery/SelectQueryBuilder.php b/src/QueryBuilder/SelectQuery/SelectQueryBuilder.php index 3eb19ad..0ee2b59 100644 --- a/src/QueryBuilder/SelectQuery/SelectQueryBuilder.php +++ b/src/QueryBuilder/SelectQuery/SelectQueryBuilder.php @@ -23,9 +23,9 @@ final class SelectQueryBuilder implements SelectQueryBuilderInterface { } - public function RelativePath(string $relativePath): SelectQueryBuilder + public function AddRelativePath(string $relativePath): SelectQueryBuilder { - $this->RelativePaths = [$relativePath]; + $this->RelativePaths[] = $relativePath; return $this; } public function RelativePaths(array $relativePaths): SelectQueryBuilder @@ -51,7 +51,7 @@ final class SelectQueryBuilder implements SelectQueryBuilderInterface public function Build(): SelectQuery { - $builder = "SELECT "; + $builder = "SELECT"; if(sizeof($this->RelativePaths)) $builder .= " " . implode(separator: ", ", array: $this->RelativePaths); if($this->From != "") $builder .= " FROM $this->From"; if($this->Where != "") $builder .= " WHERE $this->Where"; diff --git a/src/QueryBuilder/SelectQuery/SelectQueryResponse.php b/src/QueryBuilder/SelectQuery/SelectQueryResponse.php index 38f8db2..7b4271c 100644 --- a/src/QueryBuilder/SelectQuery/SelectQueryResponse.php +++ b/src/QueryBuilder/SelectQuery/SelectQueryResponse.php @@ -4,7 +4,7 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; use Darksparrow\DeegraphInteractions\DataStructures\QueryResponseRow; -class SelectQueryResponse +final class SelectQueryResponse { public array $Rows; public string $RowFormat; diff --git a/tests/QueryBuilderSelectTest.php b/tests/QueryBuilderSelectTest.php new file mode 100644 index 0000000..e4c7824 --- /dev/null +++ b/tests/QueryBuilderSelectTest.php @@ -0,0 +1,34 @@ +RelativePaths(["@path"]) + ->From("./cases/#") + ->Build() + ); + } + public function test1() + { + self::assertEquals( + expected: "SELECT clients/0/name FROM {0b368d41-7c15-42c8-899c-2b178ae9d983}/cases/0", + actual: QueryBuilder::Select() + ->AddRelativePath("clients/0/name") + ->From("{0b368d41-7c15-42c8-899c-2b178ae9d983}/cases/0") + ->Build() + ); + } +}