Cerys
4 weeks ago
16 changed files with 488 additions and 301 deletions
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; |
||||
|
|
||||
|
#[QueryBuilderQuery] |
||||
|
final class InsertQuery |
||||
|
{ |
||||
|
public string $QueryString; |
||||
|
|
||||
|
public function __construct(InsertQueryBuilder $queryBuilder) |
||||
|
{ |
||||
|
$instance = new QueryBuilderQuery(); |
||||
|
$instance->ValidateValues($queryBuilder); |
||||
|
|
||||
|
$builder = "INSERT INTO $queryBuilder->RelativePath"; |
||||
|
|
||||
|
if(sizeof($queryBuilder->Keys) > 0) $builder .= "KEYS " . implode(separator: ", ", array: $queryBuilder->Keys); |
||||
|
if(sizeof($queryBuilder->Schemas) > 0) $builder .= "SCHEMAS " . implode(separator: ", ", array: $queryBuilder->Schemas); |
||||
|
if($queryBuilder->Values != "") $builder .= "VALUES $queryBuilder->Values"; |
||||
|
if($queryBuilder->Duplicate) $builder .= "DUPLICATE"; |
||||
|
if($queryBuilder->Replace) $builder .= "REPLACE"; |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery; |
||||
|
|
||||
|
interface InsertQueryBuilderInterface |
||||
|
{ |
||||
|
public function Build() : InsertQuery; |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
||||
|
|
||||
|
class PermissionQuery |
||||
|
{ |
||||
|
protected string $QueryString; |
||||
|
|
||||
|
public function __construct(string $queryString) |
||||
|
{ |
||||
|
$this->QueryString = $queryString; |
||||
|
} |
||||
|
|
||||
|
public function RunQuery(DeegraphServer $server): PermissionQueryResponse |
||||
|
{ |
||||
|
$response = $server->RunRawRequest( |
||||
|
endpoint: "/api/v1/@query", |
||||
|
method: "POST", |
||||
|
body: $this->QueryString |
||||
|
); |
||||
|
$temp = json_decode($response, true); |
||||
|
return new PermissionQueryResponse($temp); |
||||
|
} |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; |
||||
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; |
||||
|
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; |
||||
|
|
||||
|
#[QueryBuilderQuery] |
||||
|
class PermissionQueryBuilder |
||||
|
{ |
||||
|
|
||||
|
use QueryBuilderTrait; |
||||
|
|
||||
|
#[QueryBuilderRequiredField] |
||||
|
protected string $On = ""; |
||||
|
|
||||
|
|
||||
|
#[QueryBuilderRequiredField] |
||||
|
protected string $As = ""; |
||||
|
|
||||
|
|
||||
|
public function On(string $relativePath): PermissionQueryBuilder |
||||
|
{ |
||||
|
// self::ValidateDeegraphPath(target: $relativePath); |
||||
|
$this->On = $relativePath; |
||||
|
return $this; |
||||
|
} |
||||
|
public function As(string $relativePath): PermissionQueryBuilder |
||||
|
{ |
||||
|
// self::ValidateDeegraphPath(target: $relativePath); |
||||
|
$this->As = $relativePath; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
public function Build(): PermissionQuery |
||||
|
{ |
||||
|
$builder = "PERMISSIONS "; |
||||
|
if($this->On != "") $builder .= " ON {". $this->On . "}"; |
||||
|
if($this->As != "") $builder .= " AS {". $this->As . "}"; |
||||
|
|
||||
|
return new PermissionQuery(queryString: $builder); |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery; |
||||
|
|
||||
|
interface PermissionQueryBuilderInterface |
||||
|
{ |
||||
|
public function Build() : PermissionQuery; |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery; |
||||
|
|
||||
|
class PermissionQueryResponse |
||||
|
{ |
||||
|
public bool $CanAct = false; |
||||
|
public bool $CanDelete = false; |
||||
|
public bool $CanRead = false; |
||||
|
public bool $CanWrite = false; |
||||
|
|
||||
|
public function __construct(array $deegraphResponse) |
||||
|
{ |
||||
|
foreach ($deegraphResponse["@permissions"] as $permission) |
||||
|
{ |
||||
|
switch($permission) |
||||
|
{ |
||||
|
case "ACT": |
||||
|
$this->CanAct = true; |
||||
|
break; |
||||
|
case "DELETE": |
||||
|
$this->CanDelete = true; |
||||
|
break; |
||||
|
case "READ": |
||||
|
$this->CanRead = true; |
||||
|
break; |
||||
|
case "WRITE": |
||||
|
$this->CanWrite = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
||||
|
|
||||
|
class SelectQuery |
||||
|
{ |
||||
|
protected string $QueryString; |
||||
|
|
||||
|
public function __construct(string $queryString) |
||||
|
{ |
||||
|
$this->QueryString = $queryString; |
||||
|
} |
||||
|
|
||||
|
public function RunQuery(DeegraphServer $server): array |
||||
|
{ |
||||
|
$response = $server->RunRawRequest( |
||||
|
endpoint: "/api/v1/@query", |
||||
|
method: "POST", |
||||
|
body: $this->QueryString |
||||
|
); |
||||
|
$temp = json_decode($response, true); |
||||
|
return $temp; |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; |
||||
|
|
||||
|
interface SelectQueryBuilderInterface |
||||
|
{ |
||||
|
public function Build() : SelectQuery; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; |
||||
|
|
||||
|
use Darksparrow\DeegraphInteractions\DataStructures\QueryResponseRow; |
||||
|
|
||||
|
class SelectQueryResponse |
||||
|
{ |
||||
|
public array $Rows; |
||||
|
public string $RowFormat; |
||||
|
|
||||
|
public function __construct(array $response) |
||||
|
{ |
||||
|
foreach($response["@rows"] as $row) |
||||
|
$this->Rows[] = new QueryResponseRow(array: $row); |
||||
|
$this->RowFormat = $response["@row_format"]; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue