mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
增加快捷查询方法
This commit is contained in:
@@ -972,6 +972,156 @@ class Query
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定Null查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNull($field, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'null', null);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定NotNull查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotNull($field, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'notnull', null);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定Exists查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereExists($condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->options['where'][strtoupper($logic)][] = ['exists', $condition];
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定NotExists查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotExists($condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->options['where'][strtoupper($logic)][] = ['not exists', $condition];
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定In查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereIn($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'in', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定NotIn查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotIn($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'not in', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定Like查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereLike($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'like', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定NotLike查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotLike($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'not like', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定Between查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereBetween($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'between', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定NotBetween查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotBetween($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'not between', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定Exp查询条件
|
||||||
|
* @access public
|
||||||
|
* @param mixed $field 查询字段
|
||||||
|
* @param mixed $condition 查询条件
|
||||||
|
* @param string $logic 查询逻辑 and or xor
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereExp($field, $condition, $logic = 'AND')
|
||||||
|
{
|
||||||
|
$this->parseWhereExp($logic, $field, 'exp', $condition);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分析查询表达式
|
* 分析查询表达式
|
||||||
* @access public
|
* @access public
|
||||||
@@ -984,6 +1134,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
protected function parseWhereExp($logic, $field, $op, $condition, $param = [])
|
protected function parseWhereExp($logic, $field, $op, $condition, $param = [])
|
||||||
{
|
{
|
||||||
|
$logic = strtoupper($logic);
|
||||||
if ($field instanceof \Closure) {
|
if ($field instanceof \Closure) {
|
||||||
$this->options['where'][$logic][] = is_string($op) ? [$op, $field] : $field;
|
$this->options['where'][$logic][] = is_string($op) ? [$op, $field] : $field;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user