Browse Source

query runner now returns back an object

pull/1/head
Cerys 6 months ago
parent
commit
a9c7402c67
  1. 9
      src/Core/DeegraphServer.php
  2. 21
      src/DataStructures/QueryResponseWrapper.php

9
src/Core/DeegraphServer.php

@ -2,6 +2,7 @@
namespace Darksparrow\DeegraphPHP\Core;
use Darksparrow\DeegraphPHP\DataStructures\QueryResponseWrapper;
use Darksparrow\DeegraphPHP\DataStructures\ServerInfo;
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\InsertQuery;
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\PutQuery;
@ -73,17 +74,15 @@ class DeegraphServer
/**
* @param InsertQuery|PutQuery|SelectQuery $query Takes in a Query Builder object.
* @return void
* @return QueryResponseWrapper
*/
public function RunQuery(InsertQuery|PutQuery|SelectQuery $query): void
public function RunQuery(InsertQuery|PutQuery|SelectQuery $query): QueryResponseWrapper
{
echo $query;
echo "<br><br><br>";
$response = $this->RunRawRequest(
endpoint: "/api/v1/@query",
method: "POST",
body: $query
);
var_dump($response);
return QueryResponseWrapper::FromAPIResponse($response);
}
}

21
src/DataStructures/QueryResponseWrapper.php

@ -0,0 +1,21 @@
<?php
namespace Darksparrow\DeegraphPHP\DataStructures;
class QueryResponseWrapper
{
public array $Rows;
public string $RowFormat;
public static function FromAPIResponse(string $response): QueryResponseWrapper
{
$temp = json_decode($response, true);
$builder = new QueryResponseWrapper();
$builder->Rows = $temp["@rows"];
$builder->RowFormat = $temp["@row_format"];
return $builder;
}
}
Loading…
Cancel
Save