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"; | 
				
			|||
 | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -1,84 +1,89 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
#[QueryBuilderQuery] | 
				
			|||
final class InsertQuery | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    #[QueryBuilderRequiredField] | 
				
			|||
    protected string $RelativePath = ""; | 
				
			|||
 | 
				
			|||
    protected array $Keys = []; | 
				
			|||
 | 
				
			|||
    protected array $Schemas = []; | 
				
			|||
 | 
				
			|||
    protected string $Values = ""; | 
				
			|||
 | 
				
			|||
    protected bool $Duplicate = false; | 
				
			|||
 | 
				
			|||
    protected bool $Replace = false; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function __toString(): string | 
				
			|||
    { | 
				
			|||
        $instance = new QueryBuilderQuery(); | 
				
			|||
        $instance->ValidateValues($this); | 
				
			|||
 | 
				
			|||
        $builder = "INSERT INTO $this->RelativePath"; | 
				
			|||
 | 
				
			|||
        if(sizeof($this->Keys) > 0) $builder .= "KEYS " . implode(separator: ", ", array: $this->Keys); | 
				
			|||
        if(sizeof($this->Schemas) > 0) $builder .= "SCHEMAS " . implode(separator: ", ", array: $this->Schemas); | 
				
			|||
        if($this->Values != "") $builder .= "VALUES $this->Values"; | 
				
			|||
        if($this->Duplicate) $builder .= "DUPLICATE"; | 
				
			|||
        if($this->Replace) $builder .= "REPLACE"; | 
				
			|||
 | 
				
			|||
        return $builder; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function RelativePath(string $relativePath): InsertQuery | 
				
			|||
    { | 
				
			|||
        self::ValidateDeegraphPath(target: $relativePath); | 
				
			|||
        $this->RelativePath = $relativePath; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Keys(string $keys): InsertQuery | 
				
			|||
    { | 
				
			|||
        $this->Keys = $keys; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Schemas(string $schemas): InsertQuery | 
				
			|||
    { | 
				
			|||
        $this->Schemas = $schemas; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Values(string $values): InsertQuery | 
				
			|||
    { | 
				
			|||
        $this->Values .= $values; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Duplicate(): InsertQuery | 
				
			|||
    { | 
				
			|||
        $this->Duplicate = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Replace(): InsertQuery | 
				
			|||
    { | 
				
			|||
        $this->Replace = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
#[QueryBuilderQuery] | 
				
			|||
final class InsertQueryBuilder implements InsertQueryBuilderInterface | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    #[QueryBuilderRequiredField] | 
				
			|||
    protected string $RelativePath = ""; | 
				
			|||
 | 
				
			|||
    protected array $Keys = []; | 
				
			|||
 | 
				
			|||
    protected array $Schemas = []; | 
				
			|||
 | 
				
			|||
    protected string $Values = ""; | 
				
			|||
 | 
				
			|||
    protected bool $Duplicate = false; | 
				
			|||
 | 
				
			|||
    protected bool $Replace = false; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function __toString(): string | 
				
			|||
    { | 
				
			|||
 | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function RelativePath(string $relativePath): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        self::ValidateDeegraphPath(target: $relativePath); | 
				
			|||
        $this->RelativePath = $relativePath; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Keys(string $keys): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Keys = $keys; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Schemas(string $schemas): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Schemas = $schemas; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Values(string $values): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Values .= $values; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Duplicate(): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Duplicate = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Replace(): InsertQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Replace = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Build(): InsertQuery | 
				
			|||
    { | 
				
			|||
        $instance = new QueryBuilderQuery(); | 
				
			|||
        $instance->ValidateValues($this); | 
				
			|||
 | 
				
			|||
        $builder = "INSERT INTO $this->RelativePath"; | 
				
			|||
 | 
				
			|||
        if(sizeof($this->Keys) > 0)     $builder .= "KEYS " . implode(separator: ", ", array: $this->Keys); | 
				
			|||
        if(sizeof($this->Schemas) > 0)  $builder .= "SCHEMAS " . implode(separator: ", ", array: $this->Schemas); | 
				
			|||
        if($this->Values != "")         $builder .= "VALUES $this->Values"; | 
				
			|||
        if($this->Duplicate)            $builder .= "DUPLICATE"; | 
				
			|||
        if($this->Replace)              $builder .= "REPLACE"; | 
				
			|||
 | 
				
			|||
        return $builder; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
            } | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -1,113 +1,113 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException; | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException; | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
final class PutQuery | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    protected string $PutWhat = ""; | 
				
			|||
    protected string $PutAt = ""; | 
				
			|||
    protected string $PutInto = ""; | 
				
			|||
    protected bool $Safe = false; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderRequiredFieldIsNotSetException | 
				
			|||
     */ | 
				
			|||
    public function __toString(): string | 
				
			|||
    { | 
				
			|||
        $builder = "PUT"; | 
				
			|||
        if($this->PutWhat != "") $builder .= " $this->PutWhat"; | 
				
			|||
 | 
				
			|||
        if($this->PutAt != "") $builder .= " $this->PutAt"; | 
				
			|||
        elseif ($this->PutInto != "") $builder .= " $this->PutInto"; | 
				
			|||
        else throw new QueryBuilderRequiredFieldIsNotSetException(); | 
				
			|||
 | 
				
			|||
        if($this->Safe) $builder .= " SAFE"; | 
				
			|||
        return $builder; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function Schema(string $uri): PutQuery | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "SCHEMA \"$uri\"", | 
				
			|||
            pattern: "/SCHEMA \".+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function URI(string $uri): PutQuery | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "URI \"$uri\"", | 
				
			|||
            pattern: "/URI \".+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function DataURI(string $mimeType, string $data): PutQuery | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "URI \"data:$mimeType;$data\"", | 
				
			|||
            pattern: "/URI \"data:[a-zA-Z0-9]/[a-zA-Z0-9];.+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     * @throws QueryBuilderConflictingFieldAlreadyExistsException | 
				
			|||
     */ | 
				
			|||
    public function At(string $node, string $uwu): PutQuery | 
				
			|||
    { | 
				
			|||
        self::EnsureNotSet($this->PutInto); | 
				
			|||
        $this->PutAt = self::RegexValidate( | 
				
			|||
            target: 'AT {' . $node . '}/' . $uwu, | 
				
			|||
            pattern: "/AT {[a-zA-Z0-9\-]+}\/[a-zA-Z0-9]+/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     * @throws QueryBuilderConflictingFieldAlreadyExistsException | 
				
			|||
     */ | 
				
			|||
    public function Into(string $relativePath, string $propertyName): PutQuery | 
				
			|||
    { | 
				
			|||
        self::EnsureNotSet($this->PutAt); | 
				
			|||
        $this->PutInto = self::RegexValidate( | 
				
			|||
            target: "INTO \"$relativePath\" AS \"$propertyName\"", | 
				
			|||
            pattern: "/INTO \"[a-zA-Z0-9\-]+\" AS \"[a-zA-Z0-9]+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function Safe(): PutQuery | 
				
			|||
    { | 
				
			|||
        $this->Safe = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException; | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException; | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
final class PutQueryBuilder | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    protected string $PutWhat = ""; | 
				
			|||
    protected string $PutAt = ""; | 
				
			|||
    protected string $PutInto = ""; | 
				
			|||
    protected bool $Safe = false; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderRequiredFieldIsNotSetException | 
				
			|||
     */ | 
				
			|||
    public function __toString(): string | 
				
			|||
    { | 
				
			|||
        $builder = "PUT"; | 
				
			|||
        if($this->PutWhat != "") $builder .= " $this->PutWhat"; | 
				
			|||
 | 
				
			|||
        if($this->PutAt != "") $builder .= " $this->PutAt"; | 
				
			|||
        elseif ($this->PutInto != "") $builder .= " $this->PutInto"; | 
				
			|||
        else throw new QueryBuilderRequiredFieldIsNotSetException(); | 
				
			|||
 | 
				
			|||
        if($this->Safe) $builder .= " SAFE"; | 
				
			|||
        return $builder; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function Schema(string $uri): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "SCHEMA \"$uri\"", | 
				
			|||
            pattern: "/SCHEMA \".+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function URI(string $uri): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "URI \"$uri\"", | 
				
			|||
            pattern: "/URI \".+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     */ | 
				
			|||
    public function DataURI(string $mimeType, string $data): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->PutWhat = self::RegexValidate( | 
				
			|||
            target: "URI \"data:$mimeType;$data\"", | 
				
			|||
            pattern: "/URI \"data:[a-zA-Z0-9]/[a-zA-Z0-9];.+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     * @throws QueryBuilderConflictingFieldAlreadyExistsException | 
				
			|||
     */ | 
				
			|||
    public function At(string $node, string $uwu): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        self::EnsureNotSet($this->PutInto); | 
				
			|||
        $this->PutAt = self::RegexValidate( | 
				
			|||
            target: 'AT {' . $node . '}/' . $uwu, | 
				
			|||
            pattern: "/AT {[a-zA-Z0-9\-]+}\/[a-zA-Z0-9]+/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderInvalidInputException | 
				
			|||
     * @throws QueryBuilderConflictingFieldAlreadyExistsException | 
				
			|||
     */ | 
				
			|||
    public function Into(string $relativePath, string $propertyName): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        self::EnsureNotSet($this->PutAt); | 
				
			|||
        $this->PutInto = self::RegexValidate( | 
				
			|||
            target: "INTO \"$relativePath\" AS \"$propertyName\"", | 
				
			|||
            pattern: "/INTO \"[a-zA-Z0-9\-]+\" AS \"[a-zA-Z0-9]+\"/" | 
				
			|||
        ); | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function Safe(): PutQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Safe = true; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -1,66 +1,62 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; | 
				
			|||
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator; | 
				
			|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
#[QueryBuilderQuery] | 
				
			|||
final class SelectQuery | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    #[QueryBuilderRequiredField] | 
				
			|||
    protected array $RelativePaths = []; | 
				
			|||
    protected string $From = ""; | 
				
			|||
    protected string $Where = ""; | 
				
			|||
    protected string $InstanceOf = ""; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @throws QueryBuilderRequiredFieldIsNotSetException | 
				
			|||
     */ | 
				
			|||
    public function __toString(): string | 
				
			|||
    { | 
				
			|||
        $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"; | 
				
			|||
        if($this->InstanceOf != "") $builder .= " INSTANCEOF $this->InstanceOf"; | 
				
			|||
 | 
				
			|||
        return $builder; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function RelativePath(string $relativePath): SelectQuery | 
				
			|||
    { | 
				
			|||
        $this->RelativePaths = [$relativePath]; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function RelativePaths(array $relativePaths): SelectQuery | 
				
			|||
    { | 
				
			|||
        $this->RelativePaths = $relativePaths; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function From(string $target): SelectQuery | 
				
			|||
    { | 
				
			|||
        $this->From = "" . $target; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function Where(string $target, DeegraphEqualityOperator $operator, string $value): SelectQuery | 
				
			|||
    { | 
				
			|||
        $this->Where = "" . $target . " " . $operator->value . " " . $value; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function InstanceOf(string $schema): SelectQuery | 
				
			|||
    { | 
				
			|||
        $this->InstanceOf = "" . $schema; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; | 
				
			|||
 | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery; | 
				
			|||
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField; | 
				
			|||
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator; | 
				
			|||
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
#[QueryBuilderQuery] | 
				
			|||
final class SelectQueryBuilder implements SelectQueryBuilderInterface | 
				
			|||
{ | 
				
			|||
    use QueryBuilderTrait; | 
				
			|||
 | 
				
			|||
    #[QueryBuilderRequiredField] | 
				
			|||
    protected array $RelativePaths = []; | 
				
			|||
    protected string $From = ""; | 
				
			|||
    protected string $Where = ""; | 
				
			|||
    protected string $InstanceOf = ""; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    public function __construct() | 
				
			|||
    { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function RelativePath(string $relativePath): SelectQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->RelativePaths = [$relativePath]; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function RelativePaths(array $relativePaths): SelectQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->RelativePaths = $relativePaths; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function From(string $target): SelectQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->From = "" . $target; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function Where(string $target, DeegraphEqualityOperator $operator, string $value): SelectQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->Where = "" . $target . " " . $operator->value . " " . $value; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
    public function InstanceOf(string $schema): SelectQueryBuilder | 
				
			|||
    { | 
				
			|||
        $this->InstanceOf = "" . $schema; | 
				
			|||
        return $this; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function Build(): SelectQuery | 
				
			|||
    { | 
				
			|||
        $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"; | 
				
			|||
        if($this->InstanceOf != "") $builder .= " INSTANCEOF $this->InstanceOf"; | 
				
			|||
 | 
				
			|||
        return new SelectQuery(queryString: $builder); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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