This commit is contained in:
as2252258@163.com
2021-03-27 03:29:38 +08:00
parent 0e10ee2f75
commit 08f8f417d5
3 changed files with 511 additions and 494 deletions
+4 -1
View File
@@ -313,8 +313,11 @@ class ActiveQuery extends Component implements ISqlBuilder
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
public function delete(): bool public function delete($getSql = false): string|bool
{ {
if ($getSql) {
return $this->builder->delete();
}
return $this->execute($this->builder->all())->delete(); return $this->execute($this->builder->all())->delete();
} }
} }
+14
View File
@@ -123,6 +123,20 @@ class SqlBuilder extends Component
} }
/**
* @return string
* @throws Exception
*/
public function delete()
{
$delete = sprintf('DELETE FROM %s ', $this->query->modelClass::getTable());
$this->query->from = null;
return $delete . $this->_prefix(true);
}
/** /**
* @param $attributes * @param $attributes
* @return array * @return array
+1 -1
View File
@@ -34,7 +34,7 @@ trait QueryTrait
public ?int $offset = NULL; public ?int $offset = NULL;
public ?int $limit = NULL; public ?int $limit = NULL;
public string $group = ''; public string $group = '';
public string|Closure|ActiveQuery $from = ''; public string|Closure|ActiveQuery|null $from = '';
public string $alias = 't1'; public string $alias = 't1';
public array $filter = []; public array $filter = [];