Replaces the where statement. The statement
will be reformatted to match, allowing further
chaining by Monga.

@param array $where An array of where conditions

@return object $this
9029
public function setWhere(array $where)
    {
        // When the statement is empty set the
        // where property to null to prevent
        // empty statement errors.
        if (empty($where)) {
            // delete the current where statement
            $this->where = null;

            // Skip further execution
            return $this;
        }

        // Ensure the base $or clause
        if (! isset($where['$or'])) {
            // wrap the statement in an $or clause
            $where = ['$or' => [$where]];
        }

        // Fetch the last clause in the $or array
        // to allow further chaining it's required
        // to be wrapped in an @and statement.
        $lastClause = array_pop($where['$or']);

        if (! isset($lastClause['$and'])) {
            // Wrap in an @and statement
            $lastClause = ['$and' => [$lastClause]];
        }

        // Re-append the $and clause
        $where['$or'][] = $lastClause;

        // Replace the base where statement
        $this->where = $where;

        return $this;
    }
1209322
public function parseWhere($where)
    {
        if (empty($where)) {
            $where = [];
        }

        $filter = [];
        foreach ($where as $logic => $val) {
            foreach ($val as $field => $value) {
                if ($value instanceof \Closure) {
                    // 使用闭包查询
                    $query = new MongoQuery($this->connection);
                    call_user_func_array($value, [& $query]);
                    $filter[$logic][] = $this->parseWhere($query->getOptions('where'));
                } else {
                    if (strpos($field, '|')) {
                        // 不同字段使用相同查询条件（OR）
                        $array = explode('|', $field);
                        foreach ($array as $k) {
                            $filter['$or'][] = $this->parseWhereItem($k, $value);
                        }
                    } elseif (strpos($field, '&')) {
                        // 不同字段使用相同查询条件（AND）
                        $array = explode('&', $field);
                        foreach ($array as $k) {
                            $filter['$and'][] = $this->parseWhereItem($k, $value);
                        }
                    } else {
                        // 对字段使用表达式查询
                        $field = is_string($field) ? $field : '';
                        $filter[$logic][] = $this->parseWhereItem($field, $value);
                    }
                }
            }
        }
        return $filter;
    }
547718
public function deleteByConditions( $where = array() ){
		$conditions	= $this->getConditionQuery( $where, FALSE, FALSE, FALSE );						//  render WHERE conditions, uncursored, without functions
		$query	= 'DELETE FROM '.$this->getTableName().' WHERE '.$conditions;
		$result	= $this->dbc->exec( $query );
		$this->defocus();
		return $result;
	}
791592
public function deleteWhere(array $where)
    {
        $this->applyScope();

        $this->applyConditions($where);

        $deleted = $this->model->delete();

        event(new RepositoryEntityDeleted($this, $this->model->getModel()));

        $this->resetModel();

        return $deleted;
    }
370512
public static function removeExpired(array $where = array())
    {
        // Check if we either have no revisions enabled, or it is set to infinite
        if(static::$revisionCount <= 0)
        {
            // Remove nothing
            return TRUE;
        }

        // Otherwise look for the expired revisions
        if( static::hasAlternateRevisionTable())
        {
            $query = \DB::table(static::$revisionTable);
        }
        else
        {
            $query = self::onlyTrashed();
        }

        // Were there any where clause filters?
        if(count($where)>0)
        {
            // There were, so add them in
            foreach($where as $key => $value)
            {
                $query->where($key, '=', $value);
            }
        }

        // Were there any columns that were defined as a "key column"
        if(count(static::$keyColumns) > 0)
        {
            // There were, so add in the group bys
            foreach(static::$keyColumns as $column)
            {
                $query->groupBy($column);
            }

            // Send back all of the key columns where we have more than the allowed
            $query->having(\DB::raw('count(1)'), '>', static::$revisionCount)
                ->addSelect(static::$keyColumns);
        }
        else
        {
            $query->where(\DB::raw('count(1)'), '>', static::$revisionCount);
        }

        // List of all of the ids affected by the revision count
        $ids = array();

        // Cycle through the list
        foreach($query->get() as $row)
        {
            // Otherwise look for the expired revisions
            if(static::hasAlternateRevisionTable())
            {
                $filter = \DB::table(static::$revisionTable);
            }
            else
            {
                $filter = self::onlyTrashed();
            }

            //
            foreach(static::$keyColumns as $column)
            {
                $filter->where($column, '=', $row->$column);
            }

            $filter->skip(static::$revisionCount)

                // Take as many as we need
                ->take(PHP_INT_MAX)

                // Grab anything that was soft deleted after the number we keep
                ->orderBy('created_at', 'desc')

                // Grab the ID column
                ->addSelect('id');

            // Cycle through all of the records
            foreach($filter->get() as $id)
            {
                $ids[] = $id->id;
            }
        }

        // Were there any records that fit the criteria
        if(count($ids) > 0)
        {
            // There were, so 
            if(static::hasAlternateRevisionTable())
            {
                $delete = \DB::table(static::$revisionTable);
            }
            else
            {
                $delete = self::onlyTrashed();
            }

            // Filter all of the selected
            $delete->whereIn('id', $ids);

            // Figure out how we should delete
            if(static::hasAlternateRevisionTable())
            {
                // Alternate table, so just delete it
                $delete->delete();
            }
            else
            {
                // Otherwise delete it
                $delete->forceDelete();
            }
        }

        return TRUE;
    }
1078183
public function destroy(array $where) {
        $where = $this->_createWhereClause($where, 'AND', false);
        try {
            /**
             * First, see if the user is allowed to update everything
             */
            $this->_checkAcl('destroy');
            $this->_model->delete($where);
        } catch (Garp_Auth_Exception $e) {
            /**
             * If that fails, check if the user is allowed to update her own material
             * AND if the current item is hers.
             */
            $this->_checkAcl('destroy_own');

            /**
             * Good, the user is allowed to 'destroy_own'. In that case we have to check
             * if the current item is actually the user's.
             */
            $rows = $this->_model->fetchAll($where);
            foreach ($rows as $row) {
                if (!$this->_itemBelongsToUser($row->toArray())) {
                    throw new Garp_Auth_Exception(
                        'You are only allowed to delete your own material.'
                    );
                }
                $row->delete();
            }
        }
    }
1214867
public function each($table, $fields, $where)
    {
    	$query = "SELECT $fields FROM {$table} ".mysql_args_compile($where);
//    	echo "$query\n";
		$this->query($query);
		$this->each_result = $this->result;
		return $this;
    }
983998
public function whereRaw($where, $bind = [], $logic = 'AND')
    {
        if ($bind) {
            $this->bindParams($where, $bind);
        }

        $this->options['where'][$logic][] = $this->raw($where);

        return $this;
    }
833560
protected function fixSql($where)
    {
        if ($where == parent::NO_MATCH_SQL) {
            return parent::MATCH_ALL_SQL;
        } elseif ($where == parent::MATCH_ALL_SQL) {
            return parent::NO_MATCH_SQL;
        } else {
            return "NOT ($where)";
        }
    }
1207646
protected function where($where)
    {
        foreach($where as $field => $value) {
            $this->queryBuilder->where($field, $value);
        }
    }
565918
public function delete($table, array $where)
    {
        $query = "DELETE FROM `$table` WHERE ";

        $bind = array();
        foreach ($where as $column => $value) {
            $query .= "`$column` = ? AND ";
            $bind[] = $value;
        }

        $query = substr($query, 0, -5);

        // Prepare, bind and execute
        $statement = $this->prepare($query);
        foreach ($bind as $idx => $value) {
            $statement->bindValue(($idx + 1), $value, Database::typeOfValue($value));
        }

        return $statement->execute();
    }
276445
protected function applyConditions(array $where)
    {
        foreach ($where as $field => $value) {
            if (is_array($value)) {
                list($field, $condition, $val) = $value;
                $this->model = $this->model->where($field, $condition, $val);
            } else {
                $this->model = $this->model->where($field, '=', $value);
            }
        }
    }
757181
public function where()
	{
		$condition = func_get_args();
		is_array(reset($condition)) and $condition = reset($condition);

		return $this->_where($condition);
	}
581121
public function setWhere($where, array $params = array())
    {
        $this->queryBuilder->where($where);
        $this->queryBuilder->setParameters($params);
        return $this;
    }
946728
public function firstOrFailBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

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

        return $query->firstOrFail();
    }
927541
public function deleteWhere(array $wheres)
    {
        $query = $this->getSqlObject()
            ->delete()
            ->where($wheres);

        return $this->execute($query);
    }
1308533
private static function prepareStatement(array $where): array
    {
        $keys = array_keys($where);
        foreach ($keys as &$key) {
            $key = DbProxy::quoteIdentifier($key) . ' = ?';
        }
        return $keys;
    }