新增子查询方法 addSelectSub

This commit is contained in:
JaguarJack
2020-06-17 16:19:21 +08:00
parent e105492d27
commit 727640396e
2 changed files with 27 additions and 2 deletions

View File

@@ -166,11 +166,17 @@ class CatchQuery extends Query
* 额外的字段
*
* @time 2020年01月13日
* @param array $fields
* @param $fields
* @return CatchQuery
*/
public function addFields(array $fields): CatchQuery
public function addFields($fields): CatchQuery
{
if (is_string($fields)) {
$this->options['field'][] = $fields;
return $this;
}
$this->options['field'] = array_merge($this->options['field'], $fields);
return $this;
@@ -205,4 +211,19 @@ class CatchQuery extends Query
return $this;
}
/**
* 新增 Select 子查询
*
* @time 2020年06月17日
* @param callable $callable
* @param string $as
* @return $this
*/
public function addSelectSub(callable $callable, string $as)
{
$this->field(sprintf('%s as %s', $callable($this)->buildSql(), $as));
return $this;
}
}