- WIP on SQLite Adapter and migration

This commit is contained in:
mcndave committed 2023-03-27 18:38:31 +00:00
1 parent cee978ecfd
commit 9514a46ae7
14 files changed
+98 -40

No files matched your search

+1
View File
@@ -28,4 +28,5 @@ interface AdapterInterface {
public function repositoryClass() : string;
public function queryBuilderClass() : string;
public function tableSyntax() : array;
public function whitelistAttributes(array &$parameters) : void;
}
+11 -3
View File
@@ -30,9 +30,12 @@ trait DefaultAdapterTrait
return $this->database;
}
public function schemaTable(ConnectionAdapter $parent, $databaseName, string $tableName) /* : ? object */
public function schemaTable(ConnectionAdapter $adapter, $databaseName, string $tableName) : null|object
{
return Table::repository(Repository::DEFAULT_ALIAS, $parent)->where($this->escapeIdentifier('table_schema', AdapterInterface::IDENTIFIER_FIELD), $databaseName)->loadOneFromField($this->escapeIdentifier('table_name', AdapterInterface::IDENTIFIER_FIELD), $tableName);
return Table::repository(Repository::DEFAULT_ALIAS, $adapter)
->select(\Ulmus\Common\Sql::raw('this.*'))
->where($this->escapeIdentifier('table_schema', AdapterInterface::IDENTIFIER_FIELD), $databaseName)
->loadOneFromField($this->escapeIdentifier('table_name', AdapterInterface::IDENTIFIER_FIELD), $tableName);
}
public function mapFieldType(FieldDefinition $field, bool $typeOnly = false) : string
@@ -92,4 +95,9 @@ trait DefaultAdapterTrait
return $typeOnly ? $type : $type . ( isset($length) ? "($length" . ( ! empty($precision) ? ",$precision" : "" ) . ")" : "" );
}
}
public function whitelistAttributes(array &$parameters) : void
{
$parameters = array_intersect_key($parameters, array_flip(static::ALLOWED_ATTRIBUTES));
}
}
+4
View File
@@ -14,6 +14,10 @@ use Ulmus\{Entity\InformationSchema\Table, Repository, QueryBuilder};
class MsSQL implements AdapterInterface {
use DefaultAdapterTrait;
const ALLOWED_ATTRIBUTES = [
'default', 'primary_key', 'auto_increment',
];
const DSN_PREFIX = "sqlsrv";
public int $port;
+4
View File
@@ -14,6 +14,10 @@ use Ulmus\Migration\FieldDefinition;
class MySQL implements AdapterInterface {
use DefaultAdapterTrait;
const ALLOWED_ATTRIBUTES = [
'default', 'primary_key', 'auto_increment', 'update',
];
const DSN_PREFIX = "mysql";
public string $hostname;
+9 -3
View File
@@ -3,6 +3,7 @@
namespace Ulmus\Adapter;
use Ulmus\Common\PdoObject;
use Ulmus\ConnectionAdapter;
use Ulmus\Entity\Sqlite\Table;
use Ulmus\Exception\AdapterConfigurationException;
@@ -11,6 +12,9 @@ use Ulmus\{Repository, QueryBuilder, Ulmus};
class SQLite implements AdapterInterface {
use DefaultAdapterTrait;
const ALLOWED_ATTRIBUTES = [
'default', 'primary_key', 'auto_increment'
];
const DSN_PREFIX = "sqlite";
@@ -87,9 +91,11 @@ class SQLite implements AdapterInterface {
return substr($base, 0, strrpos($base, '.') ?: strlen($base));
}
public function schemaTable(string $databaseName, string $tableName) : null|object
public function schemaTable(ConnectionAdapter $adapter, string $databaseName, string $tableName) : null|object
{
return Table::repository()->loadOneFromField(Table::field('tableName'), $tableName);
return Table::repository(Repository::DEFAULT_ALIAS, $adapter)
->select(\Ulmus\Common\Sql::raw('this.*'))
->loadOneFromField(Table::field('tableName'), $tableName);
}
public function mapFieldType(FieldDefinition $field, bool $typeOnly = false) : string
@@ -197,4 +203,4 @@ class SQLite implements AdapterInterface {
$pdo->sqliteCreateFunction('month', fn($date) => ( new \DateTime($date) )->format('m'), 1);
$pdo->sqliteCreateFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
}
}
}