- WIP on first 'doc' and also minimal support for enums where added
This commit is contained in:
1 parent
497fe5547b
commit
d600908f47
22 files changed
+367
-35
No files matched your search
@@ -19,7 +19,8 @@ interface AdapterInterface {
|
||||
public function defaultEngine() : ? string;
|
||||
|
||||
public function writableValue(/* mixed */ $value); /*: mixed*/
|
||||
|
||||
|
||||
|
||||
/* public function databaseName() : string;
|
||||
public function mapFieldType(FieldDefinition $field) : string;
|
||||
public function schemaTable(string $databaseName, string $tableName) /*: object|EntityCollection
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
use Ulmus\{Entity\InformationSchema\Table, Migration\FieldDefinition, Repository, QueryBuilder};
|
||||
use Ulmus\{ConnectionAdapter, Entity\InformationSchema\Table, Migration\FieldDefinition, Repository, QueryBuilder};
|
||||
|
||||
trait DefaultAdapterTrait
|
||||
{
|
||||
@@ -30,9 +30,9 @@ trait DefaultAdapterTrait
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function schemaTable(string $databaseName, string $tableName) /* : ? object */
|
||||
public function schemaTable(ConnectionAdapter $parent, $databaseName, string $tableName) /* : ? object */
|
||||
{
|
||||
return Table::repository()->where(Table::field('schema'), $databaseName)->loadOneFromField(Table::field('name'), $tableName);
|
||||
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);
|
||||
}
|
||||
|
||||
public function mapFieldType(FieldDefinition $field, bool $typeOnly = false) : string
|
||||
|
||||
@@ -83,6 +83,9 @@ class MsSQL implements AdapterInterface {
|
||||
catch(PDOException $ex){
|
||||
throw $ex;
|
||||
}
|
||||
finally {
|
||||
$this->password = str_repeat('*', random_int(8,16));
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
@@ -212,9 +215,12 @@ class MsSQL implements AdapterInterface {
|
||||
}
|
||||
|
||||
|
||||
public function writableValue(/* mixed */ $value) /*: mixed*/
|
||||
public function writableValue(mixed $value) /*: mixed*/
|
||||
{
|
||||
switch (true) {
|
||||
case $value instanceof \UnitEnum:
|
||||
return Ulmus::convertEnum($value);
|
||||
|
||||
case is_object($value):
|
||||
return Ulmus::convertObject($value);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class MySQL implements AdapterInterface {
|
||||
throw $ex;
|
||||
}
|
||||
finally {
|
||||
$this->password = str_repeat('*', strlen($this->password));
|
||||
$this->password = str_repeat('*', random_int(8,16));
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
@@ -148,9 +148,12 @@ class MySQL implements AdapterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public function writableValue(/* mixed */ $value) /*: mixed*/
|
||||
public function writableValue(mixed $value) : mixed
|
||||
{
|
||||
switch (true) {
|
||||
case $value instanceof \UnitEnum:
|
||||
return Ulmus::convertEnum($value);
|
||||
|
||||
case is_object($value):
|
||||
return Ulmus::convertObject($value);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class SQLite implements AdapterInterface {
|
||||
return substr($base, 0, strrpos($base, '.') ?: strlen($base));
|
||||
}
|
||||
|
||||
public function schemaTable(string $databaseName, string $tableName) /* : ? object */
|
||||
public function schemaTable(string $databaseName, string $tableName) : null|object
|
||||
{
|
||||
return Table::repository()->loadOneFromField(Table::field('tableName'), $tableName);
|
||||
}
|
||||
@@ -131,9 +131,12 @@ class SQLite implements AdapterInterface {
|
||||
return $typeOnly ? $type : $type . ( $length ? "($length" . ( isset($precision) ? ",$precision" : "" ) . ")" : "" );
|
||||
}
|
||||
|
||||
public function writableValue(/* mixed */ $value) /*: mixed*/
|
||||
public function writableValue(mixed $value) /*: mixed*/
|
||||
{
|
||||
switch (true) {
|
||||
case $value instanceof \UnitEnum:
|
||||
return Ulmus::convertEnum($value);
|
||||
|
||||
case is_object($value):
|
||||
return Ulmus::convertObject($value);
|
||||
|
||||
@@ -168,6 +171,8 @@ class SQLite implements AdapterInterface {
|
||||
|
||||
public function exportFunctions(PdoObject $pdo) : void
|
||||
{
|
||||
$pdo->sqliteCreateFunction('if', fn($comparison, $yes, $no) => $comparison ? $yes : $no, 3);
|
||||
$pdo->sqliteCreateFunction('length', fn($string) => strlen($string), 1);
|
||||
$pdo->sqliteCreateFunction('lcase', fn($string) => strtolower($string), 1);
|
||||
$pdo->sqliteCreateFunction('ucase', fn($string) => strtoupper($string), 1);
|
||||
$pdo->sqliteCreateFunction('left', fn($string, $length) => substr($string, 0, $length), 2);
|
||||
|
||||
Reference in new issue
Block a user