Appends constraint string

@param string $token
@param string $column
@param string $operator
@param string $value
@param boolean $filter Whether to filter by value
@return \Krystal\Db\Sql\QueryBuilder
434082
private function createConstraint($token, $column, $operator, $value, $filter)
    {
        if (!$this->isFilterable($filter, $value)) {
            return $this;
        }

        $this->append(sprintf('%s %s %s %s ', $token, $this->quote($column), $operator, $value));
        return $this;
    }
140366
public function orWhere($column, $operator, $value, $filter = false)
    {
        return $this->createConstraint(' OR', $column, $operator, $value, $filter);
    }
631172
protected function applyFilter(
        Builder $query,
        Contracts\QueryField $field,
        string $filter,
        $value,
        $boolean = 'and'
    ): Builder
    {
        $type = $field->getType();
        if ($type && $value !== null) {
            $value = is_array($value) ? array_map([$type, 'prepareValue'], $value) : $type->prepareValue($value);
        }
        $qualifiedField = $field->getQualifiedField();
        switch ($filter) {
            case 'equal':
                $query->where($qualifiedField, '=', $value, $boolean);
                break;
            case 'not_equal':
                $query->where($qualifiedField, '<>', $value, $boolean);
                break;
            case 'in':
                $query->whereIn($qualifiedField, (array)$value, $boolean);
                break;
            case 'not_in':
                $query->whereNotIn($qualifiedField, (array)$value, $boolean);
                break;
            case 'less':
                $query->where($qualifiedField, '<', $value, $boolean);
                break;
            case 'less_or_equal':
                $query->where($qualifiedField, '<=', $value, $boolean);
                break;
            case 'greater':
                $query->where($qualifiedField, '>', $value, $boolean);
                break;
            case 'greater_or_equal':
                $query->where($qualifiedField, '>=', $value, $boolean);
                break;
            case 'between':
                $query->whereBetween($qualifiedField, (array)$value, $boolean);
                break;
            case 'not_between':
                $query->whereNotBetween($qualifiedField, (array)$value, $boolean);
                break;
            case 'begins_with':
                $query->where($qualifiedField, 'like', "{$value}%", $boolean);
                break;
            case 'not_begins_with':
                $query->where($qualifiedField, 'not like', "{$value}%", $boolean);
                break;
            case 'contains':
                $query->where($qualifiedField, 'like', "%{$value}%", $boolean);
                break;
            case 'not_contains':
                $query->where($qualifiedField, 'not like', "%{$value}%", $boolean);
                break;
            case 'ends_with':
                $query->where($qualifiedField, 'like', "%{$value}", $boolean);
                break;
            case 'not_ends_with':
                $query->where($qualifiedField, 'not like', "%{$value}", $boolean);
                break;
            case 'is_empty':
                $query->where($qualifiedField, '=', '', $boolean);
                break;
            case 'is_not_empty':
                $query->where($qualifiedField, '<>', '', $boolean);
                break;
            case 'is_null':
                $query->whereNull($qualifiedField, $boolean);
                break;
            case 'is_not_null':
                $query->whereNotNull($qualifiedField, $boolean);
                break;
        }

        //dd($query->toSql(), $query->getBindings());
        return $query;
    }
690944
public function addFilterRule(string $field, string $value, $operator = null, int $crud = READRULES)
    {
        // if an existing rule is detected, over write
        $this->rules[$field] = new FilterRule($field, $value, $operator, $crud);
    }
148095
public function addWhereIn($column, $values, $operator = 'AND', $isIn = true)
    {
        if (($n = count($values)) < 1) {
            $condition = $isIn ? '0=1' : '1=1'; // 0=1 is used because in MSSQL value alone can't be used in WHERE
        } else if (1 === $n) {
            $value = reset($values);
            if (null === $value) {
                $condition = $this->quoteColumnName($column) . ($isIn ? ' IS NULL' : ' IS NOT NULL');
            } else {
                if ($value instanceof Expression) {
                    $condition = $this->quoteColumnName($column) . ($isIn ? '=' : '!=') . $value->expression;
                } else {
                    $bk = $this->getBindKey();
                    $this->addParam($bk, $value);
                    $condition = $this->quoteColumnName($column) . ($isIn ? '=' : '!=') . $bk;
                }
            }
        } else {
            $params = [];
            foreach ($values as $value) {
                if ($value instanceof Expression) {
                    $params[] = $value->expression;
                    continue;
                }
                $params[] = $bk = $this->getBindKey();
                $this->addParam($bk, $value);
            }
            $condition = $this->quoteColumnName($column) . ($isIn ? ' IN ' : ' NOT IN ') . '(' . implode(', ', $params) . ')';
        }
        return $this->addWhere($condition, [], $operator);
    }
237717
public function orHaving($column, $operator = null, $value = null)
    {
        [$value, $operator] = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() === 2
        );

        return $this->having($column, $operator, $value, 'or');
    }
783584
public function whereColumn($a, $operator, $b = null)
    {
        $constraint = call_user_func_array(
            [Constraint::class, 'whereColumn'],
            func_get_args()
        );

        return $this->addConstraint($constraint);
    }
1318517
public function having(string $key, string $operator, $value): SelectQueryBuilder
    {
        $this->addHaving($key, $operator, $value, 'AND');
        return $this;
    }
69170
public function where($column, $operator = '=', $value = null, $boolean = 'and', array $columns = ['*'])
    {
        return $this->repository->makeQuery()->where($column, $operator, $value, $boolean, $columns)->get($columns);
    }
290314
public function orWhere($column, $value, $operator = self::EQUALS, $quote = null)
    {
        return $this->orCriteria($this->where, $column, $value, $operator, $quote);
    }
991309
public function where($column, $operator = null, $value = null, $boolean = 'and')
    {
        // Tratar alias do _id
        $column = ($column == 'id') ? '_id' : $column;

        // Here we will make some assumptions about the operator. If only 2 values are
        // passed to the method, we will assume that the operator is an equals sign
        // and keep going. Otherwise, we'll require the operator to be passed in.
        list($value, $operator) = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() == 2
        );

        // If the columns is actually a Closure instance, we will assume the developer
        // wants to begin a nested where statement which is wrapped in parenthesis.
        // We'll add that Closure to the query then return back out immediately.
        if ($column instanceof Closure) {
            return $this->whereNested($column, $boolean);
        }

        // If the given operator is not found in the list of valid operators we will
        // assume that the developer is just short-cutting the '=' operators and
        // we will set the operators to '=' and set the values appropriately.
        if ($this->invalidOperator($operator)) {
            list($value, $operator) = [$operator, '='];
        }

        // If the value is a Closure, it means the developer is performing an entire
        // sub-select within the query and we will need to compile the sub-select
        // within the where clause to get the appropriate query record results.
        // BRUNO-AKI
        //if ($value instanceof Closure) {
        //    return $this->whereSub($column, $operator, $value, $boolean);
        //}

        // If the value is "null", we will just assume the developer wants to add a
        // where null clause to the query. So, we will allow a short-cut here to
        // that method for convenience so the developer doesn't have to check.
        if (is_null($value)) {
            return $this->whereNull($column, $boolean, $operator !== '=');
        }

        // Now that we are working with just a simple query we can put the elements
        // in our array and add the query binding to our array of bindings that
        // will be bound to each SQL statements when it is finally executed.
        $type = 'Basic';

        $this->wheres[] = compact(
            'type', 'column', 'operator', 'value', 'boolean'
        );

        return $this;
    }
870929
public function orWhereJsonLength($column, $operator, $value = null)
    {
        [$value, $operator] = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() === 2
        );

        return $this->whereJsonLength($column, $operator, $value, 'or');
    }
185501
public function compare($column, $operator, $value, $filter = false)
    {
        if (!$this->isFilterable($filter, $value)) {
            return $this;
        }

        if ($value instanceof RawSqlFragmentInterface) {
            $value = $value->getFragment();
        }

        if ($value instanceof RawBindingInterface) {
            $value = $value->getTarget();
        }

        $this->append(sprintf(' %s %s %s ', $this->quote($column), $operator, $value));
        return $this;
    }
1274644
public function conditionFactory($column, $value, $operator = '=')
    {
        $currentOrIndex = isset($this->sql['where']['$or']) ? count($this->sql['where']['$or']) - 1 : 0;

        if ($this->opIsAnd) {
            if (isset($this->sql['where'][$column][$operator])) {
                throw new \InvalidArgumentException('Mongodb Where Op key Is Exists[' . $column . $operator . ']');
            }
        } else if ($this->bracketsIsOpen) {
            if (isset($this->sql['where']['$or'][$currentOrIndex][$column][$operator])) {
                throw new \InvalidArgumentException('Mongodb Where Op key Is Exists[' . $column . $operator . ']');
            }
        }

        switch ($operator) {
            case 'IN':
                // no break
            case 'NOT IN':
                empty($value) && $value = [0];
                //这边可直接跳过不组装sql，但是为了给用户提示无条件 便于调试还是加上where field in(0)
                if ($this->opIsAnd) {
                    $this->sql['where'][$column][$operator == 'IN' ? '$in' : '$nin'] = $value;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column][$operator == 'IN' ? '$in' : '$nin'] = $value;
                } else {
                    $this->sql['where']['$or'][][$column] = $operator == 'IN' ? ['$in' => $value] : ['$nin' => $value];
                }
                break;
            case 'BETWEEN':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$gt'] = $value[0];
                    $this->sql['where'][$column]['$lt'] = $value[1];
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$gt'] = $value[0];
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$lt'] = $value[1];
                } else {
                    $this->sql['where']['$or'][][$column] = ['$gt' => $value[0], '$lt' => $value[1]];
                }
                break;
            case 'NOT BETWEEN':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$lt'] = $value[0];
                    $this->sql['where'][$column]['$gt'] = $value[1];
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$lt'] = $value[0];
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$gt'] = $value[1];
                } else {
                    $this->sql['where']['$or'][][$column] = ['$lt' => $value[0], '$gt' => $value[1]];
                }
                break;
            case 'IS NULL':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$in'] = [null];
                    $this->sql['where'][$column]['$exists'] = true;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$in'] = [null];
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$exists'] = true;
                } else {
                    $this->sql['where']['$or'][][$column] = ['$in' => [null], '$exists' => true];
                }
                break;
            case 'IS NOT NULL':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$ne'] = null;
                    $this->sql['where'][$column]['$exists'] = true;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$ne'] = null;
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$exists'] = true;
                } else {
                    $this->sql['where']['$or'][][$column] = ['$ne' => null, '$exists' => true];
                }
                break;
            case '>':
                //no break;
            case '<':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column][$operator == '>' ? '$gt' : '$lt'] = $value;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column][$operator == '>' ? '$gt' : '$lt'] = $value;
                } else {
                    $this->sql['where']['$or'][][$column] = $operator == '>' ? ['$gt' => $value] : ['$lt' => $value];
                }
                break;
            case '>=':
                //no break;
            case '<=':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column][$operator == '>=' ? '$gte' : '$lte'] = $value;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column][$operator == '>=' ? '$gte' : '$lte'] = $value;
                } else {
                    $this->sql['where']['$or'][][$column] = $operator == '>=' ? ['$gte' => $value] : ['$lte' => $value];
                }
                break;
            case 'NOT LIKE':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$not'] = new Regex($value, 'i');
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$not'] = new Regex($value, 'i');
                } else {
                    $this->sql['where']['$or'][][$column] = ['$not' => new Regex($value, 'i')];
                }
                break;
            case 'LIKE':
                //no break;
            case 'REGEXP':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$regex'] = $value;
                    $this->sql['where'][$column]['$options'] = '$i';
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$regex'] = $value;
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$options'] = '$i';
                } else {
                    $this->sql['where']['$or'][][$column] = ['$regex' => $value, '$options' => '$i'];
                }
                break;
            case '!=':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column]['$ne'] = $value;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column]['$ne'] = $value;
                } else {
                    $this->sql['where']['$or'][][$column] = ['$ne' => $value];
                }
                break;
            case '=':
                if ($this->opIsAnd) {
                    $this->sql['where'][$column] = $value;
                } else if ($this->bracketsIsOpen) {
                    $this->sql['where']['$or'][$currentOrIndex][$column] = $value;
                } else {
                    $this->sql['where']['$or'][][$column] = $value;
                }
                break;
            case 'column':
                $this->sql['where']['$where'] = "this.{$column} = this.{$value}";
                break;
            case 'raw':
                $this->sql['where']['$where'] = $column;
                break;
        }
        return $this;
    }
411268
public function whereGreaterThan($column, $value, $filter = false)
    {
        return $this->where($column, '>', $value, $filter);
    }
1018535
public function whereLessThan($column, $value, $filter = false)
    {
        return $this->where($column, '<', $value, $filter);
    }
1081793
function quote($filter = array(), $join = " AND ") {
		$QUOTE_CHAR = defined('DB::USE_ANSI_SQL') ? '"' : '';

		$string = '';
		$sep = '';

		foreach ($filter as $field => $value) {
			// first break the field up into its two components
			$operator = '';
			if (is_string($field)) {
				list($field, $operator) = explode(' ', trim($field));
			}

			if (is_array($value)) {
				// quote each individual one into a string
				$ins = '';
				$insep = '';
				foreach ($value as $v) {
					$ins .= $insep . Convert::raw2sql($v);
					$insep = ',';
				}
				$value = '('.$ins.')';
			} else if (is_null($value)) {
				$value = 'NULL';
			} else if (is_string($field)) {
				$value = "'" . Convert::raw2sql($value) . "'";
			}

			if (strpos($field, '.')) {
				list($tb, $fl) = explode('.', $field);
				$string .= $sep . $QUOTE_CHAR . $tb . $QUOTE_CHAR . '.' . $QUOTE_CHAR . $fl . $QUOTE_CHAR . " $operator " . $value;
			} else {
				if (is_numeric($field)) {
					$string .= $sep . $value;
				} else {
					$string .= $sep . $QUOTE_CHAR . $field . $QUOTE_CHAR . " $operator " . $value;
				}
			}

			$sep = $join;
		}

		return $string;
	}