- Bugfixes done on MySQL adapter caused by some changes while adding Mssql.
- WIP on Repository and QueryBuilder
This commit is contained in:
parent
d12623cc5e
commit
8e91c3a418
|
@ -2,6 +2,4 @@
|
|||
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
class MariaDB extends MySQL {
|
||||
|
||||
}
|
||||
class MariaDB extends MySQL {}
|
||||
|
|
|
@ -16,11 +16,11 @@ class MySQL implements AdapterInterface {
|
|||
|
||||
public string $password;
|
||||
|
||||
public string $charset;
|
||||
public string $charset = "utf8mb4";
|
||||
|
||||
public string $unixSocket;
|
||||
public ? string $socket;
|
||||
|
||||
public int $port;
|
||||
public int $port = 3306;
|
||||
|
||||
public function __construct(
|
||||
?string $hostname = null,
|
||||
|
@ -74,8 +74,8 @@ class MySQL implements AdapterInterface {
|
|||
|
||||
public function buildDataSourceName() : string
|
||||
{
|
||||
if ( false !== ($this->unixSocket ?? false) ) {
|
||||
|
||||
if ( false !== ($this->socket ?? false) ) {
|
||||
$parts[] = "unix_socket={$this->socket}";
|
||||
}
|
||||
else {
|
||||
$parts[] = "host={$this->hostname}";
|
||||
|
@ -87,10 +87,6 @@ class MySQL implements AdapterInterface {
|
|||
|
||||
$parts[] = "dbname={$this->database}";
|
||||
|
||||
if ( $this->socket ?? false ) {
|
||||
$parts[] = "socket={$this->socket}";
|
||||
}
|
||||
|
||||
if ( $this->charset ?? false ) {
|
||||
$parts[] = "charset={$this->charset}";
|
||||
}
|
||||
|
@ -100,11 +96,11 @@ class MySQL implements AdapterInterface {
|
|||
|
||||
public function setup(array $configuration) : void
|
||||
{
|
||||
$configuration = array_change_key_case($configuration, \CASE_LOWER);
|
||||
$connection = array_change_key_case($configuration, \CASE_LOWER);
|
||||
|
||||
# Either Unix Socket is used, or Host / Port
|
||||
if ( false !== ( $this->unixSocket = $connection['unix_socket'] ?? false ) ) {
|
||||
if ( false === ( $this->hostname = $connection['host'] ?? false ) ) {
|
||||
if ( null === ( $this->socket = $connection['socket'] ?? null ) ) {
|
||||
if ( "" === ( $this->hostname = $connection['host'] ?? "" ) ) {
|
||||
throw new AdapterConfigurationException("Your `host` name is missing from your configuration array");
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,10 @@ class Id extends \Ulmus\Annotation\Property\Field {
|
|||
public function __construct()
|
||||
{
|
||||
$this->nullable = false;
|
||||
$this->type = "int";
|
||||
$this->attributes['unsigned'] = true;
|
||||
$this->attributes['primary_key'] = true;
|
||||
|
||||
parent::__construct('int');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ class PdoObject extends PDO {
|
|||
|
||||
public function select(string $sql, array $parameters = []) : PDOStatement
|
||||
{
|
||||
#dump($sql, $parameters);
|
||||
|
||||
# var_dump($sql, $parameters);
|
||||
# die();
|
||||
try {
|
||||
if ( false !== ( $statement = $this->prepare($sql) ) ) {
|
||||
$statement = $this->execute($statement, $parameters, false);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Exception;
|
||||
|
||||
class EmptyDatasetException extends \RuntimeException {}
|
|
@ -45,7 +45,7 @@ class QueryBuilder
|
|||
|
||||
public function from(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
$table = "\"$table\"";
|
||||
// $table = "\"$table\"";
|
||||
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
|
|
|
@ -21,8 +21,8 @@ class Repository
|
|||
public function __construct(string $entity, string $alias = self::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) {
|
||||
$this->entityClass = $entity;
|
||||
$this->alias = $alias;
|
||||
$this->adapter = $adapter;
|
||||
$this->queryBuilder = new QueryBuilder( $adapter->adapter() );
|
||||
$this->adapter = $adapter ?: Ulmus::$defaultAdapter;
|
||||
$this->queryBuilder = new QueryBuilder( $this->adapter->adapter() );
|
||||
$this->entityResolver = Ulmus::resolveEntity($entity);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,17 @@ class Repository
|
|||
{
|
||||
return $this->where($field, $value)->collectionFromQuery();
|
||||
}
|
||||
|
||||
public function count() : int
|
||||
{
|
||||
$this->select("count(*) as totalItem");
|
||||
|
||||
foreach(Ulmus::iterateQueryBuilder($this->selectSqlQuery()->queryBuilder) as $entityData) {
|
||||
return $entityData['totalItem'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function deleteOne()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue