- WIP on insert/update statement
This commit is contained in:
1 parent
bad5123447
commit
828daffec8
13 files changed
+311
-36
No files matched your search
+53
-1
@@ -74,12 +74,23 @@ class Repository
|
||||
|
||||
public function save(object $entity) : bool
|
||||
{
|
||||
$dataset = $entity->toArray();
|
||||
|
||||
if ( ! $entity->isLoaded() ) {
|
||||
$save = $this->insertSqlQuery($dataset)->runQuery();
|
||||
}
|
||||
else {
|
||||
$save = $this->updateSqlQuery($dataset)->runQuery();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function saveAll(EntityCollection $collection) : bool
|
||||
{
|
||||
|
||||
foreach($collection as $entity) {
|
||||
$this->save($entity);
|
||||
}
|
||||
}
|
||||
|
||||
public function yieldAll() : \Generator
|
||||
@@ -94,6 +105,20 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function insert(array $fieldlist, string $table, string $alias, ? string $schema) : self
|
||||
{
|
||||
$this->queryBuilder->insert($fieldlist, $table, $alias, $schema);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function values(array $dataset) : self
|
||||
{
|
||||
$this->queryBuilder->values($dataset);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete() : self
|
||||
{
|
||||
$this->queryBuilder->delete($this->alias);
|
||||
@@ -269,6 +294,13 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function wherePrimaryKey($value) : self
|
||||
{
|
||||
if ( null === $primaryKeyField = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() ) {
|
||||
throw new Exception\EntityPrimaryKeyUnknown("Entity has no field containing attributes 'primary_key'");
|
||||
}
|
||||
}
|
||||
|
||||
protected function collectionFromQuery() : EntityCollection
|
||||
{
|
||||
$class = $this->entityClass;
|
||||
@@ -287,6 +319,26 @@ class Repository
|
||||
return Ulmus::runQuery($this->queryBuilder);
|
||||
}
|
||||
|
||||
protected function insertSqlQuery(array $dataset) : self
|
||||
{
|
||||
if ( ! $this->queryBuilder->has(Query\Insert::class) ) {
|
||||
$this->insert(array_keys($dataset));
|
||||
}
|
||||
|
||||
$this->values(count($dataset));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function updateSqlQuery(array $dataset) : self
|
||||
{
|
||||
if ( ! $this->queryBuilder->has(Query\Update::class) ) {
|
||||
# $this->insert();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function selectSqlQuery() : self
|
||||
{
|
||||
if ( ! $this->queryBuilder->has(Query\Select::class) ) {
|
||||
|
||||
Reference in new issue
Block a user