buildCompare

@param string|int     $key
@param Compare        $value
@param QueryInterface $query

@return  string
517037
public static function buildCompare($key, Compare $value, QueryInterface $query = null)
    {
        $query = $query ?: DatabaseFactory::getDbo()->getQuery(true);

        if (!is_numeric($key)) {
            $value->setCompare1($key);
        }

        $value->setHandler(
            function ($compare1, $compare2, $operator) use ($query) {
                return $query->format('%n ' . $operator . ' %q', $compare1, $compare2);
            }
        );

        return (string) $value;
    }
344106
public function convert(QueryCriterionInterface $query) {
        return '' .$this->setPropertyName($query->getName()) . ' ' . $this->getDriverEscaper()->reserved('object') . ' ' . $this->getOperator() . ' ';
    }
208820
private function buildQuery(Query $query): ContentfulQuery
    {
        $contentfulQuery = new ContentfulQuery();

        if (trim($query->getParameter('search_text')->getValue() ?? '') !== '') {
            $contentfulQuery->where('query', $query->getParameter('search_text')->getValue());
        }

        $optionsArray = explode('|', $query->getParameter('client')->getValue());
        if (array_key_exists(1, $optionsArray)) {
            $contentfulQuery->setContentType($optionsArray[1]);
        }

        $sortType = $query->getParameter('sort_type')->getValue();
        if ($sortType !== null) {
            $contentfulQuery->orderBy($sortType, $query->getParameter('sort_direction')->getValue());
        }

        return $contentfulQuery;
    }
1234308
protected function _buildQuery(KModelContextInterface $context)
    {
        $state = $context->getState();
        $search = $state->search;

        if ($search && !$state->isUnique())
        {
            if (strpos($search, '#ip:') === 0)
            {
                if (!in_array('ip', $this->_columns)) {
                    array_push($this->_columns, 'ip');
                }

                $state->search = str_replace('#ip:', '', $search); // cleanup for search
            }
        }

        parent::_buildQuery($context);

        if ($state->search != $search) {
            $state->search = $search; // reset search state value
        }
    }
1335755
public static function getPairsBy($key, $val, $compare = '=', $args = array())
    {
        $terms = static::getBy($key, $val, $compare, $args);
        if (!Arr::iterable($terms)) {
            return array();
        }

        return array_combine(
            Collection::pluck($terms, 'term_id'),
            Collection::pluck($terms, 'name')
        );
    }
679888
protected function match(RecordInterface $record, $query): bool
    {
        if ($record === $query) {
            //Strict search
            return true;
        }

        //Primary key comparision
        if (is_scalar($query) && $record->primaryKey() == $query) {
            return true;
        }

        //Record based comparision
        if ($query instanceof RecordInterface) {
            //Matched by PK (assuming both same class)
            if (!empty($query->primaryKey()) && $query->primaryKey() == $record->primaryKey()) {
                return true;
            }

            //Matched by content (this is a bit tricky!)
            if ($record->packValue() == $query->packValue()) {
                return true;
            }

            return false;
        }

        //Field intersection
        if (is_array($query) && array_intersect_assoc($record->packValue(), $query) == $query) {
            return true;
        }

        return false;
    }
345994
public function process(QueryInterface $query)
    {
        if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_TABLES) {
            return null;
        }

        $tablet = $this->tablet->getTablet();
        $command = new GetSchema($tablet->getAlias());
        /* @var $vtCtldResult GetSchemaResult */
        $vtCtldResult = $this->client->executeCommand($command);

        return new Tables($vtCtldResult);
    }
614148
protected function applySqlServerEquality($comparison, $query, $field, $input) {
		switch($comparison)
		{
			case '=':
				$sql = sprintf("COALESCE(%s, '') = COALESCE(%s, '')", $field, $input);
				return $query->whereRaw($sql);
			case '!=':
				$sql = sprintf("COALESCE(%s, '') != COALESCE(%s, '')", $field, $input);
				return $query->whereRaw($sql);
		}
	}
960900
public function build($query)
    {
        //clone the query so it won't be modified
        $query = clone $query;
        $parts = array();
        $this->_query = $query;
        $this->_store = $query->getRepository()->getStore();
        switch ($query->operation['type']) {
            case AnDomainQuery::QUERY_SELECT_DEFAULT :
            case AnDomainQuery::QUERY_SELECT  :
                $parts[] = $this->select($query);
                $parts[] = $this->from($query);
                $parts[] = '@MYSQL_JOIN_PLACEHOLDER';
                $parts[] = $this->where($query);
                $parts[] = $this->group($query);
                $parts[] = $this->having($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_UPDATE :
                $parts[] = $this->update($query);
                $parts[] = $this->where($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_DELETE :
                $parts[] = $this->delete($query);
                $parts[] = $this->from($query);
                $parts[] = $this->where($query);
                break;
            default :
                _die();
        }

        $string = implode(' ', $parts);
        $string = $this->parseMethods($query, $string);
        $string = str_replace('@MYSQL_JOIN_PLACEHOLDER', $this->join($query), $string);
        $string = $this->parseMethods($query, $string);

        if (!empty($query->binds)) {
            foreach ($query->binds as $key => $value) {
                $key = ':'.$key;
                $value = $this->_store->quoteValue($value);
                $string = str_replace($key, $value, $string);
            }
        }

        $string = str_replace('@DISTINCT', $query->distinct ? 'DISTINCT' : '', $string);

        return    $string;
    }
380772
public function findByKeyAndValue(string $key, $value): MapInterface
    {
        return $this->find(function (MapInterface $item) use ($key, $value): bool {
            return $item->get($key) === $value;
        });
    }
32007
public function orWhere(string $key, string $operator, $value): QueryBuilder
    {
        $this->addWhere($key, $operator, $value, 'OR');
        return $this;
    }
1162703
public ServiceInstanceQuery getEqualQueryCriterion(String key, String value){
        QueryCriterion c = new EqualQueryCriterion(key, value);
        addQueryCriterion(c);
        return this;
    }
332723
protected function _buildQueryWhere(KDatabaseQueryInterface $query)
    {
        parent::_buildQueryWhere($query);

        $state = $this->getState();

        if ($state->application) {
            $query->where('tbl.application = :application')->bind(array('application' => $state->application));
        }

        if ($state->type) {
            $query->where('tbl.type = :type')->bind(array('type' => $state->type));
        }

        if ($state->package) {
            $query->where('tbl.package IN :package')->bind(array('package' => (array) $state->package));
        }

        if ($state->name) {
            $query->where('tbl.name = :name')->bind(array('name' => $state->name));
        }

        if ($state->action) {
            $query->where('tbl.action IN (:action)')->bind(array('action' => $state->action));
        }

        if ($state->row) {
            $query->where('tbl.row IN (:row)')->bind(array('row' => $state->row));
        }

        if ($state->start_date && $state->start_date != '0000-00-00')
        {
            $start_date = $this->getObject('lib:date',array('date' => $state->start_date));

            $query->where('DATE(tbl.created_on) >= :start')->bind(array('start' => $start_date->format('Y-m-d')));

            if (is_numeric($state->day_range)) {
                $query->where('DATE(tbl.created_on) <= :range_start')->bind(array('range_start' => $start_date->modify(sprintf('+%d days', $state->day_range))->format('Y-m-d')));
            }
        }

        if ($state->end_date && $state->end_date != '0000-00-00')
        {
            $end_date  = $this->getObject('lib:date',array('date' => $state->end_date));

            $query->where('DATE(tbl.created_on) <= :end')->bind(array('end' => $end_date->format('Y-m-d')));

            if (is_numeric($state->day_range)) {
                $query->where('DATE(tbl.created_on) >= :range_end')->bind(array('range_end' => $end_date->modify(sprintf('-%d days', $state->day_range))->format('Y-m-d')));
            }
        }

        if (is_numeric($state->user)) {
            $query->where('tbl.created_by = :created_by')->bind(array('created_by' => $state->user));
        }

        if ($ip = $state->ip) {
            $query->where('tbl.ip IN (:ip)')->bind(array('ip' => $state->ip));
        }
    }
1134404
public function where($column, $comp = '=', $value = null, $boolean = 'and')
    {
        if (!static::isComporaisonOperator($comp) || is_null($value)) {
            $value = $comp;

            $comp = '=';
        }

        if ($value === null) {
            throw new QueryBuilderException('Valeur de comparaison non définie', E_ERROR);
        }

        if (!in_array(Str::lower($boolean), ['and', 'or'])) {
            throw new QueryBuilderException(
                'Le booléen '. $boolean . ' non accepté',
                E_ERROR
            );
        }

        $this->where_data_binding[$column] = $value;

        if ($this->where == null) {
            $this->where = '('. $column . ' ' . $comp . ' :' . $column . ')';
        } else {
            $this->where .= ' ' . $boolean . ' ('. $column . ' '. $comp .' :'. $column. ')';
        }

        return $this;
    }
804876
protected function mappedSelectListsKey(Builder $query, $key)
    {
        if ($this->hasColumn($key)) {
            return $query->addSelect($this->getTable() . '.' . $key);
        }

        return $query->addSelect($key);
    }
1037636
protected function buildCondition(
        Contracts\QueryEntity $meta,
        Builder $query,
        array $condition,
        $boolean = 'and'
    )
    {
        $fields = $meta->getFields();
        if (array_key_exists('data', $condition) && array_key_exists('relation', $condition['data'])) {
            $type = $fields[$condition['data']['relation']]->getType();
            if ($type instanceof Types\Relation) {
                $meta = $type->getEntity();
            } else {
                throw new RuntimeException("Field {$condition['data']['relation']} is not instance of Types\Relation");
            }
            $method = $boolean === 'or' ? 'orWhereHas' : 'whereHas';
            $query->{$method}($condition['data']['relation'], function (Builder $query) use ($meta, $condition) {
                $query->where(function (Builder $query) use ($meta, $condition) {
                    $this->getSubQuery($meta, $query, $condition['rules'], $condition['condition']);
                });
            }, ($condition['not'] ?? false ? '<' : '>='), $condition['data']['count'] ?? 1);
        } elseif (array_key_exists('condition', $condition)) {
            $query->where(function (Builder $query) use ($meta, $condition) {
                $this->getSubQuery($meta, $query, $condition['rules'], $condition['condition']);
            }, null, null, $boolean);
        } elseif (array_key_exists($condition['field'], $fields)) {
            $this->applyFilter(
                $query,
                $fields[$condition['field']],
                $condition['operator'],
                $condition['value'] ?? null,
                $boolean
            );
        } else {
            throw new RuntimeException("Field {$condition['field']} not found.");
        }
    }
804213
public function getByCondition($key, $comparator, $value = null)
    {
        $query = $this->createQuery();
        $conditionSet = $query->buildAndSet([$key, $comparator, $value]);
        return $this->getByConditionSet($conditionSet);
    }