简写方法解析.

@param array $wheres

@return array
554792
protected function resolve(array $wheres): array
    {
        $whereRecursiveCount = count($wheres, COUNT_RECURSIVE);

        //['id',1] => [['where','id',=,1]]
        if ($whereRecursiveCount === 2) {
            return [['where', $wheres[0], '=', $wheres[1]]];
        }

        //['id',>,1] => [['where','id',>,1]]
        if ($whereRecursiveCount === 3) {
            return [array_unshift($wheres, 'where')];
        }

        return $wheres;
    }
1308533
private static function prepareStatement(array $where): array
    {
        $keys = array_keys($where);
        foreach ($keys as &$key) {
            $key = DbProxy::quoteIdentifier($key) . ' = ?';
        }
        return $keys;
    }
431286
public function orWhere($wheres = array())
		{
			if (count($wheres) > 0) {
				if ( ! isset($this->wheres['$or']) or ! Arrays::is($this->wheres['$or'])) {
					$this->wheres['$or'] = array();
				}

				foreach ($wheres as $wh => $val) {
					$this->wheres['$or'][] = array($wh => $val);
				}
			}

			return $this;
		}
140389
final protected function where_group(array $wheres, $or = false, $each_or = false){
        $where_segments = [];
        foreach( $wheres as $where => $format ){
            $where_segments[] = [$this->and_or($each_or), $this->db->prepare($where, $format)];
        }
        $this->_wheres[] = [$this->and_or($or), $where_segments];
        return $this;
    }
814723
public function updateBy(array $where, array $inputs)
    {
        $inputs = $this->purifyInputs($inputs);

        $query = $this->make();

        $query = $this->applyWhere($query, $where);

        return $query->update($inputs);
    }
635440
public function findWhere(array $where, $columns = ['*'])
    {
        $this->newQuery();

        foreach ($where as $field => $value) {
            if (is_array($value)) {
                list($field, $condition, $val) = $value;
                $this->query->where($field, $condition, $val);
            }
            else {
                $this->query->where($field, '=', $value);
            }
        }

        return $this->query->get($columns);
    }
413565
protected function updateData($where)
    {
        // 自动更新
        $this->autoCompleteData($this->update);

        // 事件回调
        if (false === $this->trigger('before_update')) {
            return false;
        }

        // 获取有更新的数据
        $data = $this->getChangedData();

        if (empty($data)) {
            // 关联更新
            if (isset($this->relationWrite)) {
                $this->autoRelationUpdate();
            }

            return 0;
        } elseif ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
            // 自动写入更新时间
            $data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);

            $this->data[$this->updateTime] = $data[$this->updateTime];
        }

        if (empty($where) && !empty($this->updateWhere)) {
            $where = $this->updateWhere;
        }

        // 检查允许字段
        $allowFields = $this->checkAllowFields(array_merge($this->auto, $this->update));

        // 保留主键数据
        foreach ($this->data as $key => $val) {
            if ($this->isPk($key)) {
                $data[$key] = $val;
            }
        }

        $pk = $this->getPk();

        foreach ((array) $pk as $key) {
            if (isset($data[$key])) {
                $array[] = [$key, '=', $data[$key]];
                unset($data[$key]);
            }
        }

        if (!empty($array)) {
            $where = $array;
        }

        if ($this->relationWrite) {
            foreach ($this->relationWrite as $name => $val) {
                if (is_array($val)) {
                    foreach ($val as $key) {
                        if (isset($data[$key])) {
                            unset($data[$key]);
                        }
                    }
                }
            }
        }

        $db = $this->db(false);
        $db->startTrans();

        try {
            // 模型更新
            $result = $db->where($where)
                ->strict(false)
                ->field($allowFields)
                ->update($data);

            // 关联更新
            if (isset($this->relationWrite)) {
                $this->autoRelationUpdate();
            }

            $db->commit();

            // 更新回调
            $this->trigger('after_update');

            return $result;
        } catch (\Exception $e) {
            $db->rollback();
            throw $e;
        }
    }
777796
public function filter(array $locales)
    {
        $this->filtered = [];

        foreach ($locales as $locale) {
            $this->filterLocale($locale);
        }

        return $this->filtered;
    }
923667
private function parseWhere($wheres, &$data) {
        $sql = "";
        foreach ($wheres as $where) {
            if (isset($where[ 'child' ])) {
                if ($sql) {
                    $sql .= " " . $where[ 'logic' ];
                }
                $sql .= " (";
                $sql .= $this->parseWhere($where[ 'child' ], $data);
                $sql .= ")";
            } else {
                if ($sql) {
                    $sql .= " " . $where[ 'logic' ];
                }
                $op = $where[ 'op' ];
                if ($op == 'null') {
                    $op = "is null";
                    $sql .= " " . $where[ 'field' ] . ' ' . $op;
                } else if ($op == 'not null') {
                    $op = "is not null";
                    $sql .= " " . $where[ 'field' ] . ' ' . $op;
                } else if ($op == 'in' || $op == 'not in') {
                    $condition = $where[ 'condition' ];
                    if (!is_array($condition)) {
                        $condition = explode(',', $condition);
                    }
                    $p = [];
                    foreach ($condition as $item) {
                        $p[] .= "?";
                        $data[] = $item;
                    }
                    $p = implode(",", $p);
                    $op .= " (" . $p . ")";
                    $sql .= " " . $where[ 'field' ] . ' ' . $op;
                } else if ($op == 'between' || $op == 'not between') {
                    $sql .= " " . $where[ 'field' ] . ' ' . $op . ' ? and ? ';
                    $data[] = $where[ 'condition' ][ 0 ];
                    $data[] = $where[ 'condition' ][ 1 ];
                } else if ($op == 'day') {
                    if (is_array($where[ 'condition' ])) {
                        $sql .= " " . $where[ 'field' ] . ' ' . 'between' . ' ? and ? ';
                        $data[] = strtotime($where[ 'condition' ][ 0 ]);
                        $data[] = strtotime($where[ 'condition' ][ 1 ]);
                    } else {
                        $sql .= " " . $where[ 'field' ] . ' ' . '>' . ' ?  ';
                        $day = $where[ 'condition' ];
                        $time = strtotime(date("Y-m-d", time()));
                        $data[] = $time - $day * 24 * 60 * 60;
                    }
                } else {
                    if (key_exists($op, Where::$exp)) {
                        $op = Where::$exp[ $op ];
                    }
                    $sql .= " " . $where[ 'field' ] . ' ' . $op;
                    if ($where[ 'condition' ] === 'now') {
                        $sql .= " unix_timestamp(now()) ";
                    } else {
                        $sql .= ' ? ';
                        $data[] = $where[ 'condition' ];
                    }
                }
            }
        }
        return $sql;
    }
1237344
protected function getFreshGroupAndAggregate($wheres)
    {
        $group = [];
        $unwinds = [];

        // Add grouping columns to the $group part of the aggregation pipeline.
        if ($this->groups) {
            foreach ($this->groups as $column) {
                $group['_id'][$column] = '$' . $column;

                // When grouping, also add the $last operator to each grouped field,
                // this mimics MySQL's behaviour a bit.
                $group[$column] = ['$last' => '$' . $column];
            }

            // Do the same for other columns that are selected.
            foreach ($this->columns as $column) {
                $key = str_replace('.', '_', $column);

                $group[$key] = ['$last' => '$' . $column];
            }
        }

        // Add aggregation functions to the $group part of the aggregation pipeline,
        // these may override previous aggregations.
        if ($this->aggregate) {
            $function = $this->aggregate['function'];

            foreach ($this->aggregate['columns'] as $column) {
                // Add unwind if a subdocument array should be aggregated
                // column: subarray.price => {$unwind: '$subarray'}
                if (count($splitColumns = explode('.*.', $column)) == 2) {
                    $unwinds[] = $splitColumns[0];
                    $column = implode('.', $splitColumns);
                }

                // Translate count into sum.
                if ($function == 'count') {
                    $group['aggregate'] = ['$sum' => 1];
                } // Pass other functions directly.
                else {
                    $group['aggregate'] = ['$' . $function => '$' . $column];
                }
            }
        }

        // The _id field is mandatory when using grouping.
        if ($group && empty($group['_id'])) {
            $group['_id'] = null;
        }

        // Build the aggregation pipeline.
        $pipeline = [];
        if ($wheres) {
            $pipeline[] = ['$match' => $wheres];
        }

        // apply unwinds for subdocument array aggregation
        foreach ($unwinds as $unwind) {
            $pipeline[] = ['$unwind' => '$' . $unwind];
        }

        if ($group) {
            $pipeline[] = ['$group' => $group];
        }

        // Apply order and limit
        if ($this->orders) {
            $pipeline[] = ['$sort' => $this->orders];
        }
        if ($this->offset) {
            $pipeline[] = ['$skip' => $this->offset];
        }
        if ($this->limit) {
            $pipeline[] = ['$limit' => $this->limit];
        }
        if ($this->projections) {
            $pipeline[] = ['$project' => $this->projections];
        }

        $options = [
            'typeMap' => ['root' => 'array', 'document' => 'array'],
        ];

        // Add custom query options
        if (count($this->options)) {
            $options = array_merge($options, $this->options);
        }

        // Execute aggregation
        $results = iterator_to_array($this->collection->aggregate($pipeline, $options));

        // Return results
        return $results;
    }
1124479
public function getUserTypes(Where $where = null)
    {
        $where = Where::create("ns.nspname !~ $*", ['^pg_'])
            ->andWhere('ns.nspname != $*', ['information_schema'])
            ->andWhere($where)
            ;

        return $this->getTypes($where);
    }
1189127
protected static function parseWhere($where)
    {
        if (is_array($where) && key($where) !== 0) {
            $item = [];
            foreach ($where as $key => $val) {
                $item[] = [$key, '=', $val];
            }
            return $item;
        }
        return $where;
    }
174373
protected function _delete($where)
    {
        $params = array();
        $query = "DELETE FROM $this->_name";

        $iWhere = 0;
        $query .= " WHERE (";
        foreach ($where as $key => $value) {
            if (!is_int($key)) {
                $query .= "$key = :where$iWhere AND ";
                $params[":where$iWhere"] = $value;
                $iWhere++;
            } else {
                $query .= "$value AND";
            }
        }
        $query = substr($query, 0, -4);
        $query .= ")";

        $db = $this->db;
        $sth = $db->prepare($query);

        foreach ($params as $key => $val) {
            if (is_int($val)) {
                $sth->bindValue("$key", $val, $db::PARAM_INT);
            } else {
                $sth->bindValue("$key", $val);
            }
        }

        $response = $sth->execute();

        if ($response) {

            return true;
        }

        return false;
    }
729452
public function findWhere($where, $columns = ['*'], $with = [])
    {
        $where    = $this->castRequest($where);
        $cacheKey = $this->generateKey([$where, $columns, $with]);

        return $this->cacheResults(get_called_class(), __FUNCTION__, $cacheKey, function () use ($where, $columns, $with) {
            $model = $this->model instanceof Model ? $this->model->query() : $this->model;

            foreach ($where as $attribute => $value) {
                if (is_array($value)) {
                    list($attribute, $condition, $value) = $value;

                    $model->where($attribute, $condition, $value);
                } else {
                    $model->where($attribute, '=', $value);
                }
            }

            return $model->with($with)
                ->get($columns);
        });
    }
400763
public function prepareWhere($wheres = null)
    {
        if (isset($wheres)) {
            if (!empty($wheres)) {
                $wheres = ' WHERE '.implode(' and ', array_values($wheres));
            } else {
                $wheres = '';
            }
        } else {
            $wheres = '';
        }

        return $wheres;
    }
36293
public function delete(string $from, $wheres, array $options = [])
    {
        if (!$wheres) {
            throw new \InvalidArgumentException('Safety considerations, where conditions can not be empty');
        }

        list($where, $bindings) = DBHelper::handleConditions($wheres, $this);

        $options['from'] = $this->qn($from);
        $options['where'] = $where;

        $statement = $this->compileDelete($options);

        if (isset($options['returnSql'])) {
            return [$statement, $bindings];
        }

        return $this->fetchAffected($statement, $bindings);
    }
1113318
public function where(array $where)
    {
        $this->applyCriteria();
        $this->applyScope();

        $this->applyConditions($where);

        return $this;
    }