Skip to content

Commit

Permalink
Merge branch '1-2-0' into 'main'
Browse files Browse the repository at this point in the history
1-3-0

See merge request fluxlabs/flux-eco/storage!8
  • Loading branch information
mstuder committed Apr 26, 2022
2 parents 95da287 + 8af54dc commit 7d2bcc5
Show file tree
Hide file tree
Showing 26 changed files with 516 additions and 133 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## [1.3.0]
* feature: filter, limit, fulltextsearch

## [1.2.2]
* fix bugs in database config

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flux-eco/storage",
"description": "Handling mysql databases with json based table schemas",
"version": "1.2.2",
"version": "1.3.0",
"keywords": [
"flux-eco",
"storage",
Expand Down
19 changes: 16 additions & 3 deletions fn/getData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@

use FluxEco\Storage;

function getData(string $tableName, array $jsonSchema, string $envPrefix = '', array $filter = [], int $sequenceOffSet = 0, int $limit = 0, ?string $orderBy = null) : array
{
return Storage\Api::newFromEnv($tableName, $jsonSchema, $envPrefix)->getData($filter, $sequenceOffSet, $limit, $orderBy);
function getData(
string $tableName,
array $jsonSchema,
string $envPrefix = '',
?array $filter = null, ?int $offset = null, ?int $limit = null, ?string $orderBy = null, ?string $search = null
) : array {
$joinOperations = [];
if (key_exists('joins', $jsonSchema) && count($jsonSchema['joins']) > 0) {
foreach ($jsonSchema['joins'] as $join) {
$joinOperations[] = Storage\JoinOperationRequest::newInnerJoin(
$join['foreignTableName'],
$join['joinExpression']
);
}
}
return Storage\Api::newFromEnv($tableName, $jsonSchema, $envPrefix)->getData($filter, $offset, $limit, $orderBy, $search, $joinOperations);
}
2 changes: 1 addition & 1 deletion fn/storeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use FluxEco\Storage;

function storeData(string $tableName, array $jsonSchema, string $envPrefix = '', array $filter = [], array $data) : void
function storeData(string $tableName, array $jsonSchema, string $envPrefix = '', array $filter = [], array $data = []) : void
{
Storage\Api::newFromEnv($tableName, $jsonSchema, $envPrefix)->storeData($filter, $data);
}
2 changes: 0 additions & 2 deletions src/Adapters/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace FluxEco\Storage\Adapters;

use FluxEco\Storage\Adapters\MySqlDatabase\DatabaseConfig;
use FluxEco\Storage\Adapters;
use FluxEco\Storage\Env;
use FluxEco\Storage\Core;
use Swoole\Database\PDOConfig;

class Config implements Core\Ports\Config
{
Expand Down
19 changes: 17 additions & 2 deletions src/Adapters/MySqlDatabase/Commands/CreateStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class CreateStorageAdapter
private array $uniqueKey = [];
/** @var Column[] */
private array $ddlColumns;
private array $indexes;


/**
* @param Column[] $ddlColumns
Expand All @@ -22,12 +24,15 @@ private function __construct(
string $tableName,
?string $primaryKey = null,
array $uniqueKey,
array $ddlColumns)
array $ddlColumns,
array $indexes
)
{
$this->tableName = $tableName;
$this->primaryKey = $primaryKey;
$this->uniqueKey = $uniqueKey;
$this->ddlColumns = $ddlColumns;
$this->indexes = $indexes;
}

public static function fromApplicationCommmand(Application\Handlers\CreateStorageCommand $createStorageCommand, DdlColumnFactory $ddlColumnFactory): self
Expand All @@ -38,6 +43,7 @@ public static function fromApplicationCommmand(Application\Handlers\CreateStorag
$primaryKey = $storage->getPrimaryKey();
$uniqueKey = $storage->getUniqueKey();
$storageColumns = $storage->getColumns();
$indexes = $storage->getIndexes();
$ddlColumns = [];
foreach ($storageColumns as $storageColumn) {
$ddlColumns[] = $ddlColumnFactory->createDdlColumnfromStorageColumn($storageColumn);
Expand All @@ -47,7 +53,9 @@ public static function fromApplicationCommmand(Application\Handlers\CreateStorag
$tableName,
$primaryKey,
$uniqueKey,
$ddlColumns);
$ddlColumns,
$indexes
);
}

public function hasUniqueKey(): bool
Expand Down Expand Up @@ -82,5 +90,12 @@ final public function getUniqueKey(): array
return $this->uniqueKey;
}

public function getIndexes() : array
{
return $this->indexes;
}




}
2 changes: 2 additions & 0 deletions src/Adapters/MySqlDatabase/Factories/DdlColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function createDdlColumnfromStorageColumn(Ports\Database\Models\Column $c
return new Column\Integer($column->getName(), $column->isNullable());
case Models\TextColumn::class:
return new Column\Text($column->getName(), 0, $column->isNullable());
case Models\BlobColumn::class:
return new Column\Blob($column->getName(), 0, $column->isNullable());
case Models\VarcharColumn::class:
return new Column\Varchar($column->getName(), 255, $column->isNullable());
}
Expand Down
Loading

0 comments on commit 7d2bcc5

Please sign in to comment.