Skip to content

Commit

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

See merge request fluxlabs/flux-eco/storage!5
  • Loading branch information
mstuder committed Apr 22, 2022
2 parents 6913873 + 3ca94fd commit 577cd13
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 27 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.2.0]
* use swoole PDOConfig OR mysql_pdo

## [1.1.1]
* fix tablebuilder

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.1.1",
"version": "1.2.0",
"keywords": [
"flux-eco",
"storage",
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions src/Adapters/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FluxEco\Storage\Adapters;
use FluxEco\Storage\Env;
use FluxEco\Storage\Core;
use Swoole\Database\PDOConfig;

class Config implements Core\Ports\Config
{
Expand All @@ -29,13 +30,30 @@ private function __construct(
public static function newFromEnv(string $tableName, array $jsonSchema, string $envPrefix = '') : self
{
$apiEnv = Env::new($envPrefix);
$databaseConfig = Adapters\MySqlDatabase\DatabaseConfig::new(
$apiEnv->getHost(),
$apiEnv->getDriver(),
$apiEnv->getName(),
$apiEnv->getUser(),
$apiEnv->getPassword()
);

if(class_exists('PDOConfig')) {
$databaseConfig = (new PDOConfig())
->withHost( $apiEnv->getHost())
->withPort(3306)
// ->withUnixSocket('/tmp/mysql.sock')
->withDbName($apiEnv->getName())
->withCharset('utf8mb4')
->withUsername($apiEnv->getUser())
->withPassword($apiEnv->getPassword());
} else {
$databaseConfig = Adapters\MySqlDatabase\DatabaseConfig::new(
$apiEnv->getHost(),
$apiEnv->getDriver(),
$apiEnv->getName(),
$apiEnv->getUser(),
$apiEnv->getPassword()
);
}






$databaseClient = Adapters\MySqlDatabase\MysqlDatabaseClient::new(
$tableName,
Expand Down
5 changes: 5 additions & 0 deletions src/Adapters/MySqlDatabase/DatabaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static function new(
);
}

final public function getDbName() : string
{
return $this->database;
}

final public function getDatabase() : string
{
return $this->database;
Expand Down
12 changes: 6 additions & 6 deletions src/Adapters/MySqlDatabase/MysqlDatabaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Sql;
use Laminas\Db\TableGateway\TableGateway;

use Swoole\Database\PDOConfig;

class MysqlDatabaseClient implements Ports\Database\DatabaseClient
{
protected static array $instances = [];

private DatabaseConfig $databaseConfig;
private DatabaseConfig|PDOConfig $databaseConfig;
private Adapter $dbAdapter;
private Sql $sql;
private TableGateway $tableGateway;
private array $jsonSchema;

private function __construct(DatabaseConfig $databaseConfig, Adapter $dbAdapter, Sql $sql, TableGateway $tableGateway, array $jsonSchema)
private function __construct(DatabaseConfig|PDOConfig $databaseConfig, Adapter $dbAdapter, Sql $sql, TableGateway $tableGateway, array $jsonSchema)
{
$this->databaseConfig = $databaseConfig;
$this->dbAdapter = $dbAdapter;
Expand All @@ -37,10 +37,10 @@ private function __construct(DatabaseConfig $databaseConfig, Adapter $dbAdapter,
public static function new(
string $tableName,
array $jsonSchema,
DatabaseConfig $databaseConfig
DatabaseConfig|PDOConfig $databaseConfig
): self
{
$databaseName = $databaseConfig->getDatabase();
$databaseName = $databaseConfig->getDbname();

if (empty(static::$instances[$databaseName]) === true || empty(static::$instances[$databaseName][$tableName]) === true) {
$dbAdapter = new Adapter($databaseConfig->toArray());
Expand Down Expand Up @@ -167,7 +167,7 @@ private function addColumns(array $columns, CreateTable $table): void

final public function storageExists(Handlers\StorageExistsCommand $storageExistsCommand): bool
{
$dataBaseName = $this->databaseConfig->getDatabase();
$dataBaseName = $this->databaseConfig->getDbname();
$tableName = $storageExistsCommand->getTableName();
$dbAdapter = $this->dbAdapter;

Expand Down

0 comments on commit 577cd13

Please sign in to comment.