Compare commits
No commits in common. "f14347f01dac67b7f7d5f94c8c3aaa5a06b4bfbe" and "e4767f7c093c99cb242cbbfd20994a0f91c91aa9" have entirely different histories.
f14347f01d
...
e4767f7c09
@ -9,8 +9,6 @@ class PdoObject extends PDO {
|
||||
|
||||
public static ? string $dump = null;
|
||||
|
||||
public bool $executionStatus;
|
||||
|
||||
public function select(string $sql, array $parameters = []): PDOStatement
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
@ -31,7 +29,7 @@ class PdoObject extends PDO {
|
||||
public function runQuery(string $sql, array $parameters = []): ? PDOStatement
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
|
||||
# \debogueur([ $sql, $parameters ]);
|
||||
try {
|
||||
if (false !== ( $statement = $this->prepare($sql) )) {
|
||||
return $this->execute($statement, $parameters, true);
|
||||
@ -61,16 +59,12 @@ class PdoObject extends PDO {
|
||||
|
||||
public function execute(PDOStatement $statement, array $parameters = [], bool $commit = true): ? PDOStatement
|
||||
{
|
||||
$this->executionStatus = false;
|
||||
|
||||
try {
|
||||
if ( ! $this->inTransaction() ) {
|
||||
$this->beginTransaction();
|
||||
}
|
||||
|
||||
$this->executionStatus = empty($parameters) ? $statement->execute() : $statement->execute($parameters);
|
||||
|
||||
if ( $this->executionStatus ) {
|
||||
if (empty($parameters) ? $statement->execute() : $statement->execute($parameters)) {
|
||||
$statement->lastInsertId = $this->lastInsertId();
|
||||
|
||||
if ( $commit ) {
|
||||
|
@ -8,7 +8,7 @@ use Ulmus\Repository,
|
||||
Ulmus\Common\EntityField;
|
||||
|
||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
|
||||
use Ulmus\Annotation\Property\{ Field, Filter, FilterJoin, Relation, OrderBy, Where, OrWhere, Join, Virtual, On, WithJoin, };
|
||||
use Ulmus\Annotation\Property\{ Field, Filter, Relation, OrderBy, Where, Join, Virtual, On, WithJoin, };
|
||||
use Ulmus\Annotation\Property\Field\{ Id, ForeignKey, CreatedAt, UpdatedAt, Datetime as DateTime, Date, Time, Bigint, Tinyint, Text, Mediumtext, Longtext, };
|
||||
use Ulmus\Annotation\Property\Relation\{ Ignore as RelationIgnore };
|
||||
|
||||
@ -148,18 +148,18 @@ trait EntityTrait {
|
||||
switch (true) {
|
||||
case is_object($this->$key):
|
||||
$dataset[$realKey] = Ulmus::convertObject($this->$key);
|
||||
break;
|
||||
break;
|
||||
|
||||
case is_array($this->$key):
|
||||
$dataset[$realKey] = Ulmus::encodeArray($this->$key);
|
||||
break;
|
||||
break;
|
||||
|
||||
case is_bool($this->$key):
|
||||
$dataset[$realKey] = (int) $this->$key;
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
$dataset[$realKey] = $this->$key;
|
||||
$dataset[$realKey] = $this->$key;
|
||||
}
|
||||
}
|
||||
elseif ( $field['nullable'] ) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus;
|
||||
|
||||
use Ulmus\Annotation\Property\{Field, Where, Having, Relation, Filter, Join, FilterJoin, WithJoin, Relation\Ignore as RelationIgnore};
|
||||
use Ulmus\Annotation\Property\{Field, Where, Having, Relation, Join, WithJoin, Relation\Ignore as RelationIgnore};
|
||||
use Ulmus\Common\EntityResolver;
|
||||
|
||||
class Repository
|
||||
@ -56,19 +56,19 @@ class Repository
|
||||
return $this->collectionFromQuery();
|
||||
}
|
||||
|
||||
public function loadAllFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
|
||||
public function loadAllFromField($field, $value) : EntityCollection
|
||||
{
|
||||
return $this->loadFromField($field, $value, $operator);
|
||||
return $this->loadFromField($field, $value);
|
||||
}
|
||||
|
||||
public function loadFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
|
||||
public function loadFromField($field, $value) : EntityCollection
|
||||
{
|
||||
return $this->where($field, $value, $operator)->collectionFromQuery();
|
||||
return $this->where($field, $value)->collectionFromQuery();
|
||||
}
|
||||
|
||||
public function count() : int
|
||||
{
|
||||
$this->removeQueryFragment(Query\Select::class);
|
||||
$this->removeQueryFragment($this->queryBuilder->getFragment(Query\Select::class));
|
||||
|
||||
if ( $this->queryBuilder->getFragment(Query\GroupBy::class) ) {
|
||||
$this->select( "DISTINCT COUNT(*) OVER ()" );
|
||||
@ -84,12 +84,12 @@ class Repository
|
||||
return Ulmus::runSelectQuery($this->queryBuilder, $this->adapter)->fetchColumn(0);
|
||||
}
|
||||
|
||||
public function deleteOne()
|
||||
protected function deleteOne()
|
||||
{
|
||||
return $this->limit(1)->deleteSqlQuery()->runDeleteQuery();
|
||||
}
|
||||
|
||||
public function deleteAll()
|
||||
protected function deleteAll()
|
||||
{
|
||||
return $this->deleteSqlQuery()->runDeleteQuery();
|
||||
}
|
||||
@ -145,8 +145,6 @@ class Repository
|
||||
$primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField();
|
||||
|
||||
if ( ! $entity->isLoaded() ) {
|
||||
# $dataset = array_filter($dataset, fn($item, $field) => ! ($this->entityResolver->searchFieldAnnotation($field, new Field, false)->readonly ?? false), \ARRAY_FILTER_USE_BOTH);
|
||||
|
||||
$statement = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery();
|
||||
|
||||
if ( ( 0 !== $statement->lastInsertId ) &&
|
||||
@ -157,8 +155,6 @@ class Repository
|
||||
}
|
||||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return (bool) $statement->lastInsertId;
|
||||
}
|
||||
else {
|
||||
if ( $primaryKeyDefinition === null ) {
|
||||
@ -183,21 +179,16 @@ class Repository
|
||||
return false;
|
||||
}
|
||||
|
||||
public function saveAll(EntityCollection $collection) : int
|
||||
public function saveAll(/*EntityCollection|array*/ $collection) : void
|
||||
{
|
||||
$changed = 0;
|
||||
|
||||
foreach ($collection as $entity) {
|
||||
$this->save($entity) && $changed++;
|
||||
foreach($collection as $entity) {
|
||||
$this->save($entity);
|
||||
}
|
||||
|
||||
return $changed;
|
||||
|
||||
}
|
||||
|
||||
public function loadCollectionRelation(EntityCollection $collection, /*array|string*/ $fields) : void
|
||||
{
|
||||
foreach ((array)$fields as $name) {
|
||||
foreach((array) $fields as $name) {
|
||||
if (null !== ($relation = $this->entityResolver->searchFieldAnnotation($name, new Annotation\Property\Relation()))) {
|
||||
$relationType = strtolower(str_replace(['-', '_', ' '], '', $relation->type));
|
||||
|
||||
@ -321,7 +312,7 @@ class Repository
|
||||
}
|
||||
}
|
||||
|
||||
public function removeQueryFragment(/*? Query\Fragment|string*/ $fragment) : self
|
||||
public function removeQueryFragment(? Query\Fragment $fragment) : self
|
||||
{
|
||||
$fragment && $this->queryBuilder->removeFragment($fragment);
|
||||
|
||||
@ -577,10 +568,13 @@ class Repository
|
||||
$this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->value, $condition->operator);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
foreach($this->entityResolver->searchFieldAnnotationList($item, new Filter() ) as $filter) {
|
||||
call_user_func_array([ $this->entityClass, $filter->method ], [ $this, $item, true ]);
|
||||
}
|
||||
|
||||
>>>>>>> dc5e0885512a39387b59e8a2af37c87ff0269931
|
||||
$this->close();
|
||||
|
||||
$key = is_string($annotation->key) ? $this->entityClass::field($annotation->key) : $annotation->key;
|
||||
@ -602,10 +596,13 @@ class Repository
|
||||
$join->where(is_object($field) ? $field : $entity::field($field, $alias), $condition->value, $condition->operator);
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
foreach($this->entityResolver->searchFieldAnnotationList($item, new FilterJoin() ) as $filter) {
|
||||
call_user_func_array([ $this->entityClass, $filter->method ], [ $join, $item, true ]);
|
||||
}
|
||||
>>>>>>> dc5e0885512a39387b59e8a2af37c87ff0269931
|
||||
});
|
||||
}
|
||||
else {
|
||||
@ -819,7 +816,7 @@ class Repository
|
||||
public function createSqlQuery() : self
|
||||
{
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Create::class) ) {
|
||||
$this->queryBuilder->create($this->escapeFieldList($this->entityResolver->fieldList(EntityResolver::KEY_ENTITY_NAME, true)), $this->escapeTable($this->entityResolver->tableName()), $this->entityResolver->schemaName());
|
||||
$this->queryBuilder->create($this->escapeFieldList($this->entityResolver->fieldList()), $this->escapeTable($this->entityResolver->tableName()), $this->entityResolver->schemaName());
|
||||
}
|
||||
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Engine::class) ) {
|
||||
@ -831,16 +828,6 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function alterSqlQuery(array $fields) : self
|
||||
{
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Alter::class) ) {
|
||||
$this->queryBuilder->create($this->escapeFieldList($this->entityResolver->fieldList(EntityResolver::KEY_ENTITY_NAME, true)), $this->escapeTable($this->entityResolver->tableName()), $this->entityResolver->schemaName());
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function fromRow($row) : self
|
||||
{
|
||||
|
||||
|
@ -9,10 +9,6 @@ use Closure;
|
||||
|
||||
class RelationBuilder
|
||||
{
|
||||
const SUBQUERY_FIELD_SUFFIX = "%s\$collection";
|
||||
|
||||
const JOIN_FIELD_SEPARATOR = "%s\$";
|
||||
|
||||
protected Repository $repository;
|
||||
|
||||
protected /*object|string*/ $entity;
|
||||
|
Loading…
x
Reference in New Issue
Block a user