Compile a nested where clause.

@param  \Nova\Database\Query\Builder  $query
@param  array  $where
@return string
354574
protected function whereNested(Builder $query, $where)
    {
        $nested = $where['query'];

        return '('.substr($this->compileWheres($nested), 6).')';
    }
1178886
protected function whereSub(Builder $query, $where)
    {
        $select = $this->compileSelect($where['query']);

        return $this->wrap($where['column']).' '.$where['operator']." ($select)";
    }
816555
public function buildQuery(string $table, array $where): SqlParams
    {
        $whereClause = $this->buildWhereClause($where);
        $sql = "DELETE FROM {$table}" . $whereClause->getSql();
        return new SqlParams($sql, $whereClause->getParams());
    }
600701
protected function whereIn(Builder $query, $where)
    {
        $values = $this->valufy($where['values']);

        return $this->wrap($where['column']).' IN ['.$values.']';
    }
814862
protected function where(array $where): string
	{
		if(is_array($where['column']))
		{
			$column = '(' . $this->columns($where['column'], false) . ')';

			$value = is_array($where['value']) ? '(' . $this->params($where['value']) . ')' : $this->param($where['value']);

			return $column . ' ' . $where['operator'] . ' ' . $value;
		}

		return $this->column($where['column']) . ' ' . $where['operator'] . ' ' . $this->param($where['value']);
	}
575563
protected function prefixWheres(Builder $query, $prefix)
    {
        if (is_array($query->getQuery()->wheres))
        {
            $query->getQuery()->wheres = array_map(function($where) use($prefix)
            {
                $column = $where['column'];
                $where['column'] = ($this->isId($column)) ? $column : $prefix .'.'. $column;
                return $where;
            }, $query->getQuery()->wheres);
        }
    }
153064
protected function compileWheresToArray($query)
	{
		return (new Collection($query->wheres))->map(function ($where) use ($query) {
			return $where['boolean'].' '.$this->{"where{$where['type']}"}($query, $where);
		})->getAll();
	}
364874
public function compileDelete(Builder $query)
    {
        // keyspace-ref:
        $table = $this->wrapTable($query->from);
        // use-keys-clause:
        $keyClause = null;
        if ($query->key) {
            $key = $this->wrapKey($query->key);
            $keyClause = "USE KEYS {$key}";
        }
        // returning-clause
        $returning = implode(', ', $query->returning);
        $where = is_array($query->wheres) ? $this->compileWheres($query) : '';

        return trim("delete from {$table} {$keyClause} {$where} RETURNING {$returning}");
    }
612462
public function compileSelect(Builder $query)
    {
        if (is_null($query->columns)) $query->columns = array('*');

        return trim($this->concatenate($this->compileComponents($query)));
    }
188965
protected function compileDeleteWithoutJoins($query, $table, $where)
    {
        $sql = trim("delete from {$table} {$where}");

        // When using MySQL, delete statements may contain order by statements and limits
        // so we will compile both of those here. Once we have finished compiling this
        // we will return the completed SQL statement so it will be executed for us.
        if (! empty($query->orders)) {
            $sql .= ' '.$this->compileOrders($query, $query->orders);
        }

        if (isset($query->limit)) {
            $sql .= ' '.$this->compileLimit($query, $query->limit);
        }

        return $sql;
    }
503900
public function compileSelect(Builder $query) {
    $this->beforeGet($query);
    return $this->grammar->compileSelect($query);
  }
1252915
public function where($query, $queryParams = null, string $op = ''): self
    {
        if ($query == '') {
            throw new BuilderException('Query required!');
        }

        // sub-where
        if ($queryParams instanceof Builder) {
            // $opr argument is empty, should be exists in query (eg: id = )
            $query = $this->prepare($query, '', $queryParams);

            return $this->push('where', $query);
        }

        if (is_array($query)) {
            // eg: [['id' => ...], ...]
            foreach ($query as $field => $params) {
                // eg: ['id' => [1, '=', '?', 'or/and']], ['a.id' => [id('b.id'), ...]]
                if (is_array($params)) {
                    @ [$params, $operator, $escapeOperator, $op] = (array) $params;
                    if ($operator == null) {
                        $operator = '='; // @default=equal
                    }
                    $query = '?? '. $operator .' '. ($params instanceof Identifier ? '??' : $escapeOperator ?: '?');
                    $queryParams = [$field, $params];
                } else {
                    // eg: ['id' => 1]
                    $query = '?? = '. ($params instanceof Identifier ? '??' : '?');
                    $queryParams = [$field, $params];
                }

                $op = $op ? strtoupper($op) : self::OP_AND;
                if ($op != self::OP_OR && $op != self::OP_AND) {
                    throw new BuilderException('Available ops: OR, AND');
                }

                $query = $this->agent->prepare($query, $queryParams);

                $this->push('where', [[$query, $op]]);
            }

            return $this;
        }

        if (!is_string($query)) {
            throw new BuilderException(sprintf('String, array or Builder type queries are accepted only, %s given!',
                gettype($query)));
        }

        if ($queryParams !== null) {
            if (!is_array($queryParams) && !is_scalar($queryParams) && !($queryParams instanceof Identifier)) {
                throw new BuilderException(sprintf('Array, scalar and Query\Identifier params are accepted only, %s given!',
                    gettype($queryParams)));
            }
        }

        $query = $this->agent->prepare($query, $queryParams);

        $op = $op ? strtoupper($op) : self::OP_AND;
        if ($op != self::OP_OR && $op != self::OP_AND) {
            throw new BuilderException('Available ops: OR, AND');
        }

        return $this->push('where', [[$query, $op]]);
    }
159809
private function getSearchQueryWhere($query, $where)
	{
		foreach ($where as $key => $value) {
			$query->where($value[0], $value[1], $value[2]);
		}

		return $query;
	}
699689
public function compile_where( &$query )
	{
		$build = '';

		foreach( $query->wheres as $where ) 
		{
			// to make nested wheres possible you can pass an closure 
			// wich will create a new query where you can add your nested wheres
			if ( !isset( $where[2] ) && is_closure( $where[1] ) )
			{
				$sub_query = new Query;

				call_user_func( $where[1], $sub_query );

				// The parameters get added by the call of compile where
				$build .= ' '.$where[0].' ( '.substr( $this->compile_where( $sub_query ), 7 ).' )';

				continue;
			}

			// when we have an array as where values we have 
			// to parameterize them
			if ( is_array( $where[3] ) ) 
			{
				$where[3] = '('.$this->parameterize( $where[3] ).')';
			}
			else
			{
				$where[3] = $this->param( $where[3] );
			}

			// we always need to escepe where 1 wich referrs to the key
			$where[1] = $this->escape( $where[1] );

			// implode the beauty
			$build .= ' '.implode( ' ', $where );
		}

		return $build;
	}
55648
protected function compileWhereBasic($where)
	{
		extract($where);

		// Replace like with MongoRegex
		if ($operator == 'like') {
			$operator = '=';
			$regex    = str_replace('%', '', $value);

			// Prepare regex
			if (substr($value, 0, 1) != '%')
				$regex = '^' . $regex;
			if (substr($value, -1) != '%')
				$regex = $regex . '$';

			$value = array('$regex' => "$regex");
		}

		if (!isset($operator) || $operator == '=')
		{
			$query = array(
				$column => $value
			);
		}
		elseif (array_key_exists($operator, $this->conversion))
		{
			$query = array(
				$column => array(
					$this->conversion[$operator] => $value
				)
			);
		}
		else
		{
			$query = array(
				$column => array(
					'$' . $operator => $value
				)
			);
		}

		return $query;
	}
1061443
private function getUpdateWhere($query, &$params)
    {
        $whereArray = [];

        if (isset($query['where'])) {
            $whereArray[] = '('.$query['where'].')';
            unset($query['where']);
        }

        foreach ($query as $field => $value) {
            if ($field[0] == ':') {
                $params[$field] = $value;
                continue;
            }
            $token = ':'.$field;
            $whereArray[] = "{$field} = {$token}";
            $params[$token] = $value;
        }

        return implode(' AND ', $whereArray);
    }
330451
protected function compileWheresToArray($query)
    {
        return collect($query->wheres)->map(function ($where) use ($query) {
            return $where['boolean'].' '.$this->{"where{$where['type']}"}($query, $where);
        })->all();
    }