Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hasFields, Keys, Pluck, Values and Without manipulations #52 #69

Merged
merged 12 commits into from
Sep 9, 2018
2 changes: 1 addition & 1 deletion src/Query/Aggregation/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace TBolier\RethinkQL\Query\Aggregation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Logic\LogicTrait;
use TBolier\RethinkQL\Query\Manipulation\LogicTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function ordening(string $key): Ordening
return $this->ordering;
}

public function row(string $value): Row
public function row(string $value = null): Row
{
$this->row = new Row($this->rethink, $value);

Expand Down
12 changes: 0 additions & 12 deletions src/Query/Logic/LogicTrait.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TBolier\RethinkQL\Query\Logic;
namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
Expand All @@ -10,7 +10,7 @@
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class GetFieldLogic extends AbstractQuery
class GetField extends AbstractQuery
{
use AggregationTrait;
use OperationTrait;
Expand Down
61 changes: 61 additions & 0 deletions src/Query/Manipulation/HasFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types = 1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class HasFields extends AbstractQuery
{
use AggregationTrait;
use OperationTrait;
use TransformationTrait;

/**
* @var array
*/
private $keys;

/**
* @var QueryInterface
*/
private $query;

public function __construct(
RethinkInterface $rethink,
QueryInterface $query,
array $keys
) {
parent::__construct($rethink);

$this->rethink = $rethink;
$this->query = $query;
$this->keys = $keys;
}

public function toArray(): array
{
if (\count($this->keys) === 1) {
$keysQuery = implode($this->keys);
} else {
$keysQuery = [
TermType::MAKE_ARRAY,
array_values($this->keys)
];
}

return [
TermType::HAS_FIELDS,
[
$this->query->toArray(),
$keysQuery
]
];
}
}
43 changes: 43 additions & 0 deletions src/Query/Manipulation/Keys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types = 1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class Keys extends AbstractQuery
{
use AggregationTrait;
use TransformationTrait;

/**
* @var QueryInterface
*/
private $query;

public function __construct(
RethinkInterface $rethink,
QueryInterface $query
) {
parent::__construct($rethink);

$this->query = $query;
$this->rethink = $rethink;
}

public function toArray(): array
{
return [
TermType::KEYS,
[
$this->query->toArray()
]
];
}
}
12 changes: 12 additions & 0 deletions src/Query/Manipulation/LogicTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace TBolier\RethinkQL\Query\Manipulation;

trait LogicTrait
{
public function getField(string $field): GetField
{
return new GetField($this->rethink, $field, $this->query);
}
}
29 changes: 29 additions & 0 deletions src/Query/Manipulation/ManipulationTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\QueryInterface;

trait ManipulationTrait
{
public function pluck(...$keys): Pluck
{
return new Pluck($this->rethink, /** @scrutinizer ignore-type */ $this, $keys);
}

public function without(...$keys): Without
{
return new Without($this->rethink, /** @scrutinizer ignore-type */ $this, $keys);
}

public function keys(): Keys
{
return new Keys($this->rethink, /** @scrutinizer ignore-type */ $this);
}

public function values(): Values
{
return new Values($this->rethink, /** @scrutinizer ignore-type */ $this);
}
}
61 changes: 61 additions & 0 deletions src/Query/Manipulation/Pluck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types = 1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class Pluck extends AbstractQuery
{
use AggregationTrait;
use OperationTrait;
use TransformationTrait;

/**
* @var array
*/
private $keys;

/**
* @var QueryInterface
*/
private $query;

public function __construct(
RethinkInterface $rethink,
QueryInterface $query,
array $keys
) {
parent::__construct($rethink);

$this->query = $query;
$this->rethink = $rethink;
$this->keys = $keys;
}

public function toArray(): array
{
if (\count($this->keys) === 1) {
$keysQuery = implode($this->keys);
} else {
$keysQuery = [
TermType::MAKE_ARRAY,
array_values($this->keys)
];
}

return [
TermType::PLUCK,
[
$this->query->toArray(),
$keysQuery
]
];
}
}
52 changes: 52 additions & 0 deletions src/Query/Manipulation/RowHasFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
declare(strict_types = 1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class RowHasFields extends AbstractQuery
{
/**
* @var array
*/
private $keys;

public function __construct(
RethinkInterface $rethink,
array $keys
) {
parent::__construct($rethink);

$this->keys = $keys;
$this->rethink = $rethink;
}

public function toArray(): array
{
if (\count($this->keys) === 1) {
$keysQuery = implode($this->keys);
} else {
$keysQuery = [
TermType::MAKE_ARRAY,
array_values($this->keys)
];
}

return [
TermType::HAS_FIELDS,
[
[
TermType::IMPLICIT_VAR
],
$keysQuery
]
];
}
}
49 changes: 49 additions & 0 deletions src/Query/Manipulation/Values.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types = 1);

namespace TBolier\RethinkQL\Query\Manipulation;

use TBolier\RethinkQL\Query\AbstractQuery;
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
use TBolier\RethinkQL\Query\Operation\OperationTrait;
use TBolier\RethinkQL\Query\QueryInterface;
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
use TBolier\RethinkQL\RethinkInterface;
use TBolier\RethinkQL\Types\Term\TermType;

class Values extends AbstractQuery
{
use AggregationTrait;
use OperationTrait;
use TransformationTrait;

/**
* @var array
*/
private $keys;

/**
* @var QueryInterface
*/
private $query;

public function __construct(
RethinkInterface $rethink,
QueryInterface $query
) {
parent::__construct($rethink);

$this->query = $query;
$this->rethink = $rethink;
}

public function toArray(): array
{
return [
TermType::VALUES,
[
$this->query->toArray()
],
];
}
}
Loading