protected function subquery(Subquery $subquery, bool $enclose = true): string
	{
		$query = $subquery->getQuery();

		if($query instanceof Closure)
		{
			$builder = $query;

			$query = $this->query->newInstance()->inSubqueryContext();

			$builder($query);
		}

		$query = $query->getCompiler()->select();

		$this->params = array_merge($this->params, $query['params']);

		if($enclose)
		{
			$query['sql'] = '(' . $query['sql'] . ')';
		}

		if(($alias = $subquery->getAlias()) !== null)
		{
			$query['sql'] .= ' AS ' . $this->escapeIdentifier($alias);
		}

		return $query['sql'];
	}