Browse Source

`DELETE` query

Cerys Lewis 5 months ago
parent
commit
72c714dc56
  1. 3
      src/Interfaces/QueryBuilderInterface.php
  2. 37
      src/QueryBuilder/QueryBuilders/DeleteQueryBuilder.php
  3. 22
      src/QueryInstance/DeleteQuery.php
  4. 13
      src/QueryResponse/DeleteQueryResponse.php

3
src/Interfaces/QueryBuilderInterface.php

@ -2,6 +2,7 @@
namespace Darksparrow\DeegraphInteractions\Interfaces; namespace Darksparrow\DeegraphInteractions\Interfaces;
use Darksparrow\DeegraphInteractions\QueryInstance\DeleteQuery;
use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery; use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery;
use Darksparrow\DeegraphInteractions\QueryInstance\InsertQuery; use Darksparrow\DeegraphInteractions\QueryInstance\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryInstance\PutQuery; use Darksparrow\DeegraphInteractions\QueryInstance\PutQuery;
@ -10,5 +11,5 @@ use Darksparrow\DeegraphInteractions\QueryInstance\SelectQuery;
interface QueryBuilderInterface interface QueryBuilderInterface
{ {
// public function __construct(); // public function __construct();
public function Build(): GrantQuery|InsertQuery|PutQuery|SelectQuery; public function Build(): DeleteQuery|GrantQuery|InsertQuery|PutQuery|SelectQuery;
} }

37
src/QueryBuilder/QueryBuilders/DeleteQueryBuilder.php

@ -0,0 +1,37 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator;
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType;
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException;
use Darksparrow\DeegraphInteractions\Interfaces\QueryBuilderInterface;
use Darksparrow\DeegraphInteractions\QueryInstance\DeleteQuery;
use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery;
#[QueryBuilderQuery]
final class DeleteQueryBuilder implements QueryBuilderInterface
{
#[QueryBuilderRequiredField]
protected string $RelativePath;
/**
* @throws QueryBuilderRequiredFieldIsNotSetException
*/
public function Build(): DeleteQuery
{
$builder = "DELETE ";
if($this->RelativePath != "") $builder .= $this->RelativePath;
return new DeleteQuery(queryString: $builder);
}
public function RelativePath(string $relativePath): DeleteQueryBuilder
{
$this->RelativePath = $relativePath;
return $this;
}
}

22
src/QueryInstance/DeleteQuery.php

@ -0,0 +1,22 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryInstance;
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
use Darksparrow\DeegraphInteractions\Interfaces\QueryInstanceInterface;
use Darksparrow\DeegraphInteractions\QueryResponse\DeleteQueryResponse;
use Darksparrow\DeegraphInteractions\QueryResponse\GrantQueryResponse;
use Darksparrow\DeegraphInteractions\Superclasses\QueryInstanceSuperclass;
final class DeleteQuery extends QueryInstanceSuperclass implements QueryInstanceInterface
{
public function RunQuery(DeegraphServer $deegraphServer): DeleteQueryResponse
{
$response = $deegraphServer->RunRawRequest(
endpoint: "/api/v1/@query",
method: "POST",
body: $this->QueryString,
);
return new DeleteQueryResponse(response: $response);
}
}

13
src/QueryResponse/DeleteQueryResponse.php

@ -0,0 +1,13 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryResponse;
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface;
final class DeleteQueryResponse implements QueryResponseInterface
{
public function __construct(string $response)
{
$response = json_decode($response, true);
}
}
Loading…
Cancel
Save