Browse Source

some work on the LINK query

dev
Cerys 4 weeks ago
parent
commit
82adca3e5f
  1. 31
      src/QueryBuilder/LinkQuery/LinkQuery.php
  2. 106
      src/QueryBuilder/LinkQuery/LinkQueryBuilder.php
  3. 10
      src/QueryBuilder/LinkQuery/LinkQueryResponse.php
  4. 5
      src/QueryBuilder/QueryBuilder.php
  5. 2
      src/QueryBuilder/QueryBuilderTrait.php
  6. 85
      tests/QueryBuilderLinkTest.php

31
src/QueryBuilder/LinkQuery/LinkQuery.php

@ -0,0 +1,31 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery;
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryResponse;
class LinkQuery
{
protected string $QueryString;
public function __construct(string $queryString)
{
$this->QueryString = $queryString;
}
public function __toString()
{
return $this->QueryString;
}
public function RunQuery(DeegraphServer $server): LinkQueryResponse
{
$response = $server->RunRawRequest(
endpoint: "/api/v1/@query",
method: "POST",
body: $this->QueryString
);
$temp = json_decode($response, true);
return new LinkQueryResponse($temp);
}
}

106
src/QueryBuilder/LinkQuery/LinkQueryBuilder.php

@ -0,0 +1,106 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQueryBuilder
{
use QueryBuilderTrait;
#[QueryBuilderRequiredField]
protected string $RelativePath1 = "";
#[QueryBuilderRequiredField]
protected string $ToOrOf = "";
#[QueryBuilderRequiredField]
protected string $RelativePath2 = "";
#[QueryBuilderRequiredField]
protected string $PropertyName = "";
protected string $Mode = "";
public function LinkWhat(string $relativePath): LinkQueryBuilder
{
self::ValidateDeegraphPath(target: $relativePath);
$this->RelativePath1 = $relativePath;
return $this;
}
public function LinkTo(string $relativePath): LinkQueryBuilder
{
self::EnsureNotSet($this->RelativePath2);
self::ValidateDeegraphPath(target: $relativePath);
$this->RelativePath2 = $relativePath;
$this->ToOrOf = "TO";
return $this;
}
public function LinkOf(string $relativePath): LinkQueryBuilder
{
self::EnsureNotSet($this->RelativePath2);
self::ValidateDeegraphPath(target: $relativePath);
$this->RelativePath2 = $relativePath;
$this->ToOrOf = "OF";
return $this;
}
public function PropertyName(string $propertyName): LinkQueryBuilder
{
$this->PropertyName = $propertyName;
return $this;
}
public function Overwrite(): LinkQueryBuilder
{
self::EnsureNotSet($this->Mode);
$this->Mode = "OVERWRITE";
return $this;
}
public function Replace(): LinkQueryBuilder
{
self::EnsureNotSet($this->Mode);
$this->Mode = "REPLACE";
return $this;
}
public function Force(): LinkQueryBuilder
{
self::EnsureNotSet($this->Mode);
$this->Mode = "FORCE";
return $this;
}
public function Build(): LinkQuery
{
self::ValidateValues(target: $this);
$builder = "LINK "
. $this->RelativePath1
. " "
. $this->ToOrOf
. " "
. $this->RelativePath2
. " AS "
. $this->PropertyName;
if($this->Mode != "") $builder .= " " . $this->Mode;
return new LinkQuery(queryString: $builder);
}
}

10
src/QueryBuilder/LinkQuery/LinkQueryResponse.php

@ -0,0 +1,10 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery;
class LinkQueryResponse
{
public function __construct(array $deegraphResponse)
{
}
}

5
src/QueryBuilder/QueryBuilder.php

@ -4,6 +4,7 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
@ -35,4 +36,8 @@ final class QueryBuilder
{ {
return new ReferencesQueryBuilder(); return new ReferencesQueryBuilder();
} }
public static function Link(): LinkQueryBuilder
{
return new LinkQueryBuilder();
}
} }

2
src/QueryBuilder/QueryBuilderTrait.php

@ -8,6 +8,7 @@ use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputExceptio
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
@ -41,6 +42,7 @@ trait QueryBuilderTrait
public function ValidateValues( public function ValidateValues(
DirectoryQueryBuilder DirectoryQueryBuilder
|InsertQueryBuilder |InsertQueryBuilder
|LinkQueryBuilder
|PermissionQueryBuilder |PermissionQueryBuilder
|PutQueryBuilder |PutQueryBuilder
|ReferencesQueryBuilder |ReferencesQueryBuilder

85
tests/QueryBuilderLinkTest.php

@ -0,0 +1,85 @@
<?php
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
use PHPUnit\Framework\TestCase;
final class QueryBuilderLinkTest extends TestCase
{
private string $TestUUID = "{00000000-0000-0000-0000-000000000000}";
public function test0()
{
self::assertEquals(
expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkTo($this->TestUUID)
->PropertyName("test")
->Build()
);
}
public function test1()
{
self::assertEquals(
expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test OVERWRITE",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkTo($this->TestUUID)
->PropertyName("test")
->Overwrite()
->Build()
);
}
public function test2()
{
self::assertEquals(
expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test REPLACE",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkTo($this->TestUUID)
->PropertyName("test")
->Replace()
->Build()
);
}
public function test3()
{
self::assertEquals(
expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test FORCE",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkTo($this->TestUUID)
->PropertyName("test")
->Force()
->Build()
);
}
public function test4()
{
self::assertEquals(
expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkOf($this->TestUUID)
->PropertyName("test")
->Build()
);
}
public function test5()
{
self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class);
self::assertEquals(
expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test",
actual: QueryBuilder::Link()
->LinkWhat($this->TestUUID)
->LinkOf($this->TestUUID)
->PropertyName("test")
->Overwrite()
->Replace()
->Force()
->Build()
);
}
}
Loading…
Cancel
Save