- A lot of work done on bug fixing. Added a new SQLite adapter
This commit is contained in:
1 parent
667df92e52
commit
c14644cdda
28 files changed
+727
-234
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Repository;
|
||||
|
||||
use Ulmus\{ Query, Adapter };
|
||||
use Ulmus\Annotation\Property\Field;
|
||||
|
||||
trait EscapeTrait
|
||||
{
|
||||
public function escapeField(string $identifier) : string
|
||||
{
|
||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_FIELD);
|
||||
}
|
||||
|
||||
public function escapeFieldList(array $fieldList) : array
|
||||
{
|
||||
foreach($fieldList as &$list) {
|
||||
$list['name'] = $this->escapeField($list['name']);
|
||||
|
||||
$fieldTag = array_filter($list['tags'] ?? [], fn($item) => $item['object'] instanceof Field)[0]['object'] ?? null;
|
||||
|
||||
if ( $fieldTag && isset($fieldTag->name) ) {
|
||||
$fieldTag->name = $this->escapeField($fieldTag->name);
|
||||
}
|
||||
}
|
||||
|
||||
return $fieldList;
|
||||
}
|
||||
|
||||
public function escapeTable(string $identifier) : string
|
||||
{
|
||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_TABLE);
|
||||
}
|
||||
|
||||
public function escapeDatabase(string $identifier) : string
|
||||
{
|
||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_DATABASE);
|
||||
}
|
||||
|
||||
public function escapedDatabase() : ? string
|
||||
{
|
||||
$name = $this->entityResolver->tableAnnotation()->database ?? $this->adapter->adapter()->database ?? null;
|
||||
|
||||
return $name ? static::escapeDatabase($name) : null;
|
||||
}
|
||||
|
||||
public function escapeSchema(string $identifier) : string
|
||||
{
|
||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_SCHEMA);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Ulmus\Repository;
|
||||
use Ulmus\{ Repository, Query };
|
||||
|
||||
class MssqlRepository extends Repository {
|
||||
|
||||
/*
|
||||
protected function finalizeQuery() : void
|
||||
{
|
||||
if ( null !== $offset = $this->queryBuilder->getFragment(Query\Offset::class) ) {
|
||||
@@ -39,5 +39,34 @@ class MssqlRepository extends Repository {
|
||||
$this->queryBuilder->removeFragment($limit);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
protected function finalizeQuery() : void
|
||||
{
|
||||
if ( null !== $offset = $this->queryBuilder->getFragment(Query\MsSQL\Offset::class) ) {
|
||||
# an order by is mandatory for mssql offset/limit
|
||||
if ( null === $order = $this->queryBuilder->getFragment(Query\OrderBy::class) ) {
|
||||
$this->orderBy("(SELECT 0)");
|
||||
}
|
||||
|
||||
if ( empty ($offset->offset ) ) {
|
||||
if ( null !== $select = $this->queryBuilder->getFragment(Query\Select::class) ) {
|
||||
$select->top = $offset->limit;
|
||||
}
|
||||
elseif ( null !== $delete = $this->queryBuilder->getFragment(Query\Delete::class) ) {
|
||||
$delete->top = $offset->limit;
|
||||
}
|
||||
|
||||
$this->queryBuilder->removeFragment($offset);
|
||||
}
|
||||
elseif ( empty($offset->limit) ) {
|
||||
throw new \Exception("Your offset query fragment is missing a LIMIT value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function serverRequestCountRepository() : Repository
|
||||
{
|
||||
return new static($this->entityClass, $this->alias, $this->adapter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Repository;
|
||||
|
||||
use Ulmus\{Common\EntityResolver, ConnectionAdapter, QueryBuilder, Repository, Query, Ulmus};
|
||||
|
||||
class MysqlRepository extends Repository {
|
||||
|
||||
public function pragma(/*object|Stringable*/ $pragma, $argument = null, bool $callable = false) : self
|
||||
{
|
||||
$this->queryBuilder->pragma($pragma, $argument, $callable);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function createSqlQuery() : self
|
||||
{
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Engine::class) ) {
|
||||
if ( $engine = $this->entityResolver->tableAnnotation()->engine ?? $this->entityResolver->databaseAdapter()->adapter()->defaultEngine() ) {
|
||||
$this->queryBuilder->engine($engine);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::createSqlQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Repository;
|
||||
|
||||
use Ulmus\{ConnectionAdapter, QueryBuilder, Repository, Query, Ulmus};
|
||||
|
||||
class SqliteRepository extends Repository {
|
||||
|
||||
public function pragma(/*object|Stringable*/ $pragma, $argument = null, bool $callable = false) : self
|
||||
{
|
||||
$this->queryBuilder->pragma($pragma, $argument, $callable);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function finalizeQuery() : void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function serverRequestCountRepository() : Repository
|
||||
{
|
||||
return new static($this->entityClass, $this->alias, $this->adapter);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user