WIP on docs and added basic enums supports

This commit is contained in:
mcndave committed 2023-01-14 02:19:42 +00:00
1 parent 497fe5547b
commit b6752f4364
22 files changed
+367 -35

No files matched your search

+52 -11
View File
@@ -38,7 +38,7 @@ class Repository
public function loadOne() : ? object
{
return $this->limit(1)->collectionFromQuery()[0] ?? null;
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0] ?? null;
}
public function loadOneFromField($field, $value) : ? object
@@ -53,7 +53,7 @@ class Repository
public function loadAll() : EntityCollection
{
return $this->collectionFromQuery();
return $this->selectSqlQuery()->collectionFromQuery();
}
public function loadAllFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
@@ -63,7 +63,7 @@ class Repository
public function loadFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
{
return $this->where($field, $value, $operator)->collectionFromQuery();
return $this->selectSqlQuery()->where($field, $value, $operator)->collectionFromQuery();
}
public function count() : int
@@ -278,7 +278,7 @@ class Repository
$this->finalizeQuery();
$result = Ulmus::runSelectQuery($this->queryBuilder, $this->adapter);
# ??? $result = Ulmus::runSelectQuery($this->queryBuilder, $this->adapter);
return $this;
}
@@ -288,12 +288,26 @@ class Repository
return $this->createSqlQuery()->runQuery();
}
public function listTables(? string $database = null)
{
return $this->showTablesSqlQuery($database)->runQuery();
}
public function listColumns(? string $table = null)
{
$table ??= $this->entityResolver->tableName();
$this->showColumnsSqlQuery($table);
return $this->collectionFromQuery(Entity\InformationSchema\Column::class);
}
public function generateDatasetDiff(object $entity, bool $oldValues = false) : array
{
$array = array_change_key_case($entity->toArray());
$dataset = array_change_key_case($entity->entityGetDataset(false, true));
# dump($array, $dataset);
return array_udiff_assoc($oldValues ? $dataset : $array , $oldValues ? $array : $dataset, function($e1, $e2) {
if ( is_array($e1) ) {
if (is_array($e2)) {
@@ -584,7 +598,9 @@ class Repository
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field['name'], new RelationIgnore) ) {
$escAlias = $this->escapeIdentifier($alias);
$this->select("$escAlias.$key as $alias\${$field['name']}");
$name = $entity::resolveEntity()->searchFieldAnnotation($field['name'], new Field())->name ?? $field['name'];
$this->select("$escAlias.$key as $alias\${$name}");
}
}
@@ -785,14 +801,12 @@ class Repository
public function collectionFromQuery(? string $entityClass = null) : EntityCollection
{
$class = $entityClass ?: $this->entityClass;
$class = $entityClass ?? $this->entityClass;
$entityCollection = $this->instanciateEntityCollection();
$this->selectSqlQuery();
$entityCollection = $class::entityCollection();
$this->finalizeQuery();
foreach(Ulmus::iterateQueryBuilder($this->queryBuilder, $this->adapter) as $entityData) {
$entityCollection->append( ( new $class() )->resetVirtualProperties()->entityFillFromDataset($entityData) );
}
@@ -916,6 +930,33 @@ class Repository
return $this;
}
public function showDatabasesSqlQuery() : self
{
if ( null === $this->queryBuilder->getFragment(Query\Show::class) ) {
$this->queryBuilder->showDatabases();
}
return $this;
}
public function showTablesSqlQuery() : self
{
if ( null === $this->queryBuilder->getFragment(Query\Show::class) ) {
$this->queryBuilder->showTables();
}
return $this;
}
public function showColumnsSqlQuery(string $table) : self
{
if ( null === $this->queryBuilder->getFragment(Query\Show::class) ) {
$this->queryBuilder->showColumns($table);
}
return $this;
}
protected function fromRow($row) : self
{