Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^7.1",
"ext-pdo": "*",
"event-engine/php-persistence": "^0.3"
"event-engine/php-persistence": "^0.4"
},
"require-dev": {
"roave/security-advisories": "dev-master",
Expand Down
54 changes: 54 additions & 0 deletions src/Index/RawSqlIndexCmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

namespace EventEngine\DocumentStore\Postgres\Index;

use EventEngine\DocumentStore\Index;
use EventEngine\DocumentStore\Postgres\Exception\InvalidArgumentException;

final class RawSqlIndexCmd implements Index
{
/**
* @var string|null
*/
private $name;

/**
* @var string
*/
private $sql;

public static function fromArray(array $data): Index
{
if(!array_key_exists('sql', $data)) {
throw new InvalidArgumentException("Data array misses raw sql stmt!");
}

return new self($data['sql'], $data['name'] ?? null);
}

public function __construct(string $sql, string $name = null)
{
$this->sql = $sql;
$this->name = $name;
}


public function toArray()
{
return [
'sql' => $this->sql,
'name' => $this->name,
];
}

public function sql(): string
{
return $this->sql;
}

public function name(): ?string
{
return $this->name;
}
}
19 changes: 19 additions & 0 deletions src/Metadata/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace EventEngine\DocumentStore\Postgres\Metadata;

final class Column
{
private $sql;

public function __construct(string $sql)
{
$this->sql = $sql;
}

public function sql(): string
{
return $this->sql;
}
}
75 changes: 75 additions & 0 deletions src/Metadata/MetadataColumnIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);

namespace EventEngine\DocumentStore\Postgres\Metadata;

use EventEngine\DocumentStore\Index;
use EventEngine\DocumentStore\Postgres\Exception\InvalidArgumentException;

final class MetadataColumnIndex implements Index
{
/**
* @var Column[]
*/
private $columns;

/**
* @var Index
*/
private $indexCmd;

public static function fromArray(array $data): Index
{
if(!array_key_exists('column', $data)) {
throw new InvalidArgumentException('Missing key columns in index data');
}

if(!array_key_exists('index', $data)) {
throw new InvalidArgumentException('Missing key index in data');
}

if(!array_key_exists('indexClass', $data)) {
throw new InvalidArgumentException('Missing key indexClass in data');
}

$indexClass = $data['indexClass'];
$index = $indexClass::fromArray($data['index']);

return new self($index, ...array_map(function (string $columnSql) {
return new Column($columnSql);
}, $data['columns']));
}

public function __construct(Index $indexCmd, Column ...$columns)
{
$this->columns = $columns;
$this->indexCmd = $indexCmd;
}

/**
* @return Column[]
*/
public function columns(): array
{
return $this->columns;
}

/**
* @return Index
*/
public function indexCmd(): Index
{
return $this->indexCmd;
}

public function toArray()
{
return [
'columns' => array_map(function (Column $column) {
return $column->sql();
}, $this->columns),
'index' => $this->indexCmd->toArray(),
'indexClass' => get_class($this->indexCmd),
];
}
}
Loading