Cleaning.

This commit is contained in:
Greyscale 2020-05-21 19:16:50 +02:00
parent 284f12e16f
commit 7ed3853707
55 changed files with 25 additions and 20 deletions

0
src/Abstracts/Model.php Executable file → Normal file
View file

0
src/Abstracts/Service.php Executable file → Normal file
View file

21
src/Abstracts/TableGateway.php Executable file → Normal file
View file

@ -103,19 +103,17 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
*/
public function saveInsert(Model $model)
{
#\Kint::dump($this->getAutoIncrementKeys(), $this->getSql()->getAdapter()->getDriver()->getDatabasePlatformName());
switch($this->getSql()->getAdapter()->getDriver()->getDatabasePlatformName()){
switch ($this->getSql()->getAdapter()->getDriver()->getDatabasePlatformName()) {
case 'Postgresql':
$data = $model->__toRawArray();
foreach($this->getAutoIncrementKeys() as $autoIncrementKey){
foreach ($this->getAutoIncrementKeys() as $autoIncrementKey) {
unset($data[$autoIncrementKey]);
}
break;
default:
$data = $model->__toRawArray();
}
#\Kint::dump($data);exit;
$this->insert($data);
if ($model->hasPrimaryKey()) {
@ -124,11 +122,11 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
$pk = [];
switch($this->getSql()->getAdapter()->getDriver()->getDatabasePlatformName()){
switch ($this->getSql()->getAdapter()->getDriver()->getDatabasePlatformName()) {
case 'Postgresql':
foreach ($model->getPrimaryKeys_dbColumns() as $primaryKey => $dontCare) {
$sequenceId = sprintf(
"\"%s_%s_seq\"",
'"%s_%s_seq"',
$this->getTable(),
$primaryKey
);
@ -139,7 +137,8 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
->getDriver()
->getConnection()
->getResource()
->lastInsertId($sequenceId);
->lastInsertId($sequenceId)
;
}
break;
@ -148,8 +147,8 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
$pk[$primaryKey] = $this->getLastInsertValue();
}
}
return $pk;
return $pk;
}
/**
@ -391,12 +390,14 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
public function fetchRandom()
{
$resultSet = $this->select(function (Select $select) {
switch($this->adapter->getDriver()->getDatabasePlatformName()){
switch ($this->adapter->getDriver()->getDatabasePlatformName()) {
case 'MySQL':
$select->order(new Expression('RAND()'));
break;
case 'Postgresql':
$select->order(new Expression('RANDOM()'));
break;
default:
throw new BenzineException("Can't fetchRandom for a {$this->adapter->getDriver()->getDatabasePlatformName()} type database!");

4
src/Components/Column.php Executable file → Normal file
View file

@ -288,12 +288,12 @@ class Column extends Entity
*/
public function setDbType($dbType)
{
$this->dbType = $dbType;
switch(strtolower($this->dbType)){
switch (strtolower($this->dbType)) {
case 'user-defined':
$this->dbType = 'enum';
break;
}

0
src/Components/Entity.php Executable file → Normal file
View file

13
src/Components/Model.php Executable file → Normal file
View file

@ -312,13 +312,14 @@ class Model extends Entity
;
// Decide on the permitted values
switch($this->getDbAdaptor()->getDriver()->getDatabasePlatformName()){
switch ($this->getDbAdaptor()->getDriver()->getDatabasePlatformName()) {
case 'Mysql':
$oColumn->setPermittedValues($column->getErrata('permitted_values'));
break;
case 'Postgresql':
if($column->getDataType() == 'USER-DEFINED') {
$enumName = explode("::", $column->getColumnDefault(), 2)[1];
if ('USER-DEFINED' == $column->getDataType()) {
$enumName = explode('::', $column->getColumnDefault(), 2)[1];
$permittedValues = [];
foreach ($this->getAdaptor()->query("SELECT unnest(enum_range(NULL::{$enumName})) AS option")->execute() as $aiColumn) {
$permittedValues[] = $aiColumn['option'];
@ -340,24 +341,28 @@ class Model extends Entity
switch ($column->getDataType()) {
case 'bigint': // mysql & postgres
$oColumn->setMaxFieldLength(9223372036854775807);
break;
case 'int': // mysql
case 'integer': // postgres
case 'serial': // postgres
$oColumn->setMaxFieldLength(2147483647);
break;
case 'mediumint': // mysql
$oColumn->setMaxFieldLength(8388607);
break;
case 'smallint': // mysql & postgres
$oColumn->setMaxFieldLength(32767);
break;
case 'tinyint': // mysql
$oColumn->setMaxFieldLength(127);
break;
default:
$oColumn->setMaxLength($column->getCharacterMaximumLength());
}
$this->columns[$oColumn->getPropertyName()] = $oColumn;

0
src/Components/RelatedModel.php Executable file → Normal file
View file

0
src/Db.php Executable file → Normal file
View file

0
src/Exception/DBTypeNotTranslatedException.php Executable file → Normal file
View file

0
src/Exception/Exception.php Executable file → Normal file
View file

0
src/Exception/SchemaToAdaptorException.php Executable file → Normal file
View file

0
src/Generator/clean Executable file → Normal file
View file

0
src/Generator/laminator Executable file → Normal file
View file

0
src/Generator/phpcsfixerfier Executable file → Normal file
View file

0
src/Generator/sdkifier Executable file → Normal file
View file

View file

View file

View file

View file

2
src/Generator/templates/Models/basemodel.php.twig Executable file → Normal file
View file

@ -58,11 +58,13 @@ abstract class Base{{ class_name }}Model extends AbstractModel implements ModelI
{% endif %}
{% for column in columns %}
// PHPType: {{ column.getPhpType }}. DBType: {{ column.getDbType }}. Max Length: {{ column.getMaxFieldLength }}.
{% if column.default_value %}
protected ?{{ column.getPhpType }} ${{ column.getFieldSanitised }} = '{{ column.default_value }}';
{% else %}
protected ?{{ column.getPhpType }} ${{ column.getFieldSanitised }} = null;
{% endif %}
{% endfor %}
{% for related_object in related_objects %}

0
src/Generator/templates/Models/basetable.php.twig Executable file → Normal file
View file

0
src/Generator/templates/Models/model.php.twig Executable file → Normal file
View file

0
src/Generator/templates/Models/table.php.twig Executable file → Normal file
View file

0
src/Generator/templates/Models/tests.models.php.twig Executable file → Normal file
View file

0
src/Generator/templates/Router/route.php.twig Executable file → Normal file
View file

View file

View file

View file

View file

View file

View file

0
src/Generator/templates/SDK/Dockerfile.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/Models/basemodel.php.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/Models/model.php.twig Executable file → Normal file
View file

View file

View file

View file

View file

View file

View file

0
src/Generator/templates/SDK/bootstrap.php.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/client.php.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/composer.json.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/docker-compose.yml.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/gitignore.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/phpunit.xml.twig Executable file → Normal file
View file

0
src/Generator/templates/SDK/readme.md.twig Executable file → Normal file
View file

0
src/Generator/templates/Services/baseservice.php.twig Executable file → Normal file
View file

0
src/Generator/templates/Services/service.php.twig Executable file → Normal file
View file

View file

0
src/Generator/templates/_overwrite_warning.twig Executable file → Normal file
View file

0
src/Generator/wait-for-db Executable file → Normal file
View file

0
src/Interfaces/ModelInterface.php Executable file → Normal file
View file

5
src/Laminator.php Executable file → Normal file
View file

@ -284,7 +284,7 @@ class Laminator
public static function getAutoincrementColumns(DbAdaptor $adapter, $table)
{
switch($adapter->getDriver()->getDatabasePlatformName()){
switch ($adapter->getDriver()->getDatabasePlatformName()) {
case 'Mysql':
$sql = "SHOW columns FROM `{$table}` WHERE extra LIKE '%auto_increment%'";
$query = $adapter->query($sql);
@ -295,7 +295,6 @@ class Laminator
}
return $columns;
case 'Postgresql':
$sql = "SELECT column_name FROM information_schema.COLUMNS WHERE TABLE_NAME = '{$table}' AND column_default LIKE 'nextval(%'";
$query = $adapter->query($sql);
@ -306,11 +305,9 @@ class Laminator
}
return $columns;
default:
throw new Exception("Don't know how to get autoincrement columns for {$adapter->getDriver()->getDatabasePlatformName()}!");
}
}
/**

0
src/Twig/Extensions/ArrayUniqueTwigExtension.php Executable file → Normal file
View file