Browse Source

`GRANT` and `SELECT` examples now shadow the deegraph docs

Cerys Lewis 5 months ago
parent
commit
50934994a6
  1. 28
      examples/grantQuery.php
  2. 42
      examples/selectQuery.php

28
examples/grantQuery.php

@ -1,17 +1,37 @@
<?php <?php
// https://github.com/owoalex/deegraph/blob/main/docs/query-grant.md#examples
global $db; global $db;
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../examples/connection.php'; require_once __DIR__ . '/../examples/connection.php';
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator;
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType; use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery;
function Example0(): GrantQuery
{
$queryBuilder = QueryBuilder::Grant()
->Permissions(permissionTypes: [
DeegraphPermissionType::WRITE,
DeegraphPermissionType::READ,
])
->On(target: "*")
->IsDelegatable();
QueryBuilder::Grant() return $queryBuilder->Build();
}
function Example1(): GrantQuery
{
$queryBuilder = QueryBuilder::Grant()
->GrantAll() ->GrantAll()
->On(target: "*") ->On(target: "*")
->Bu($db); ->IsDelegatable();
return $queryBuilder->Build();
}
$result = $db->RunQuery($grantQuery); $result = Example0()->RunQuery($db);
var_dump($result); var_dump($result);

42
examples/selectQuery.php

@ -0,0 +1,42 @@
<?php
// https://github.com/owoalex/deegraph/blob/main/docs/query-select.md#examples
global $db;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../examples/connection.php';
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryInstance\SelectQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
function Example0(): SelectQuery
{
$queryBuilder = QueryBuilder::Select()
->RelativePath(relativePath: ".")
->Where(target: "name", operator: DeegraphEqualityOperator::IS, value: "Peter Evans")
->From("**");
return $queryBuilder->Build();
}
function Example1(): SelectQuery
{
$queryBuilder = QueryBuilder::Select()
->RelativePaths(relativePaths: [
"email_address",
"name",
])
->Where(target: "display_name", operator: DeegraphEqualityOperator::IS, value: "Peter")
->From("**")
->InstanceOf(schema: "https://schemas.auxiliumsoftware.co.uk/v1/user.json");
return $queryBuilder->Build();
}
$result = Example0()->RunQuery($db);
foreach($result->FlattenRows() as $row)
{
echo "$row\n";
}
Loading…
Cancel
Save