Compare commits

...

2 Commits

Author SHA1 Message Date
Cerys Lewis f0de6b3702 aligning 5 months ago
Cerys Lewis 72c714dc56 `DELETE` query 5 months ago
  1. 3
      src/Interfaces/QueryBuilderInterface.php
  2. 25
      src/QueryBuilder/QueryBuilder.php
  3. 37
      src/QueryBuilder/QueryBuilders/DeleteQueryBuilder.php
  4. 22
      src/QueryInstance/DeleteQuery.php
  5. 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;
} }

25
src/QueryBuilder/QueryBuilder.php

@ -2,6 +2,7 @@
namespace Darksparrow\DeegraphInteractions\QueryBuilder; namespace Darksparrow\DeegraphInteractions\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\DeleteQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\GrantQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\GrantQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQueryBuilder;
@ -9,23 +10,9 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQueryBuild
final class QueryBuilder final class QueryBuilder
{ {
public static function Grant(): GrantQueryBuilder public static function Delete(): DeleteQueryBuilder { return new DeleteQueryBuilder(); }
{ public static function Grant(): GrantQueryBuilder { return new GrantQueryBuilder(); }
return new GrantQueryBuilder(); public static function Insert(): InsertQueryBuilder { return new InsertQueryBuilder(); }
} public static function Put(): PutQueryBuilder { return new PutQueryBuilder(); }
public static function Select(): SelectQueryBuilder { return new SelectQueryBuilder(); }
public static function Insert(): InsertQueryBuilder
{
return new InsertQueryBuilder();
}
public static function Put(): PutQueryBuilder
{
return new PutQueryBuilder();
}
public static function Select(): SelectQueryBuilder
{
return new SelectQueryBuilder();
}
} }

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