@param ResourceRecord[] $queries

@return ResourceRecord[]

@throws UnsupportedTypeException
496220
public function getAnswer(array $queries): array
    {
        $answer = [];
        foreach ($queries as $query) {
            $answer = array_merge($answer, $this->getRecordsRecursively($query));
        }

        return $answer;
    }
816153
public function queryProcessing($queryParams) 
    {
        $driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
        //drivers = Array ( [0] => mysql [1] => oci [2] => pgsql [3] => sqlite [4] => sqlsrv )
        switch ($driver) {
        case 'mysql':
            list($this->query, $this->totalQuery, $this->filterQuery)
                = MySQLDataSource::processQuery($this->query, $queryParams);
            break;
        case 'oci':
            list($this->query, $this->totalQuery, $this->filterQuery)
                = OracleDataSource::processQuery($this->query, $queryParams);
            break;
        case 'pgsql':
            list($this->query, $this->totalQuery, $this->filterQuery)
                = PostgreSQLDataSource::processQuery($this->query, $queryParams);
            break;
        case 'sqlsrv':
            list($this->query, $this->totalQuery, $this->filterQuery)
                = SQLSRVDataSource::processQuery($this->query, $queryParams);
            break;
        default:
            break;
        }
        $this->countTotal = Util::get($queryParams, 'countTotal', false);
        $this->countFilter = Util::get($queryParams, 'countFilter', false);
        return $this;
    }
838378
public function selectOne( $query, $bindings = [ ], $useReadPdo = true, $resultClass = null )
	{
		$records = $this->select( $query, $bindings, $useReadPdo, $resultClass );
		return array_shift( $records );
	}
500872
public function select( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_results( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}
273258
private function getRecordsByHandle(array $records): array
    {
        $recordsByHandle = [];
        foreach ($records as $record) {
            $modelClass = get_class($record);
            $converter = Craft::$app->controller->module->getConverter($modelClass);
            $index = $converter->getRecordIndex($record);
            $recordsByHandle[$index] = $record;
        }

        return $recordsByHandle;
    }
884067
protected function parseSub($query)
    {
        if ($query instanceof self || $query instanceof EloquentBuilder) {
            return [$query->toSql(), $query->getBindings()];
        } elseif (is_string($query)) {
            return [$query, []];
        } else {
            throw new InvalidArgumentException;
        }
    }
776536
private static function getQueriableResource($type, array $options = [])
    {
        if (!array_key_exists($type, self::$cache['resources']) || self::haveOptionsBeenUpdated($type, $options)) {
            self::$cache['options'][$type] = $options;
            self::$cache['resources'][$type] = new QueriableResource($type, $options);
        }
        return self::$cache['resources'][$type];
    }
1363625
protected static function unionQueriesToOne($queries)
    {
        if (count($queries) === 0) {
            throw new Exception(Module::t('app', 'Nothing to union'));
        }

        $query = array_reduce(
            $queries,
            function ($query, $item) {
                /**
                 * @var $query Query
                 */
                if ($query === null) {
                    $query = $item;
                } else {
                    $query->union($item);
                }
                return $query;
            }
        );

        return $query;
    }
1130835
protected function findWildcardEntry(ResourceRecord $query): array
    {
        $labels = explode('.', rtrim($query->getName(), '.'));
        $labels = array_reverse($labels);

        /** @var ResourceRecord[] $wildcards */
        $wildcards = [];
        $array = &$this->wildcardRecords;
        foreach ($labels as $label) {
            if (array_key_exists($label, $array)) {
                $array = &$array[$label];
                continue;
            }

            if (array_key_exists('*', $array)) {
                $wildcards = $array['*'][$query->getClass()][$query->getType()] ?? [];
            }
        }

        $answers = [];
        foreach ($wildcards as $wildcard) {
            $rr = clone $wildcard;
            $rr->setName($query->getName());
            $answers[] = $rr;
        }

        return $answers;
    }
1100811
private function _or($queries)
    {
        $this->where['$or'] = array();
        $length = count($queries);
        for ($i = 0; $i < $length; $i++)
        {
            $this->where['$or'][] = $queries[$i]->where;
        }

        return $this;
    }
145995
public function sourceQuery($params)
    {
        if ($this->hasMethod('sourceRecords')) {
            return $this->sourceRecords($params, null, null)->dataQuery();
        } else {
            user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
        }
    }
1196575
public function buildSearchArray($queryParameters)
    {
        $allowedStringCriteria = array('name', 'dateFrom', 'dateTo');
        $allowedArrayCriteria = array('types');
        $criteria = array();

        foreach ($queryParameters as $parameter => $value) {
            if (in_array($parameter, $allowedStringCriteria) && is_string($value)) {
                $criteria[$parameter] = $value;
            } elseif (in_array($parameter, $allowedArrayCriteria) && is_array($value)) {
                $criteria[$parameter] = $value;
            }
        }

        return $criteria;
    }
860992
public function search(array $types, array $query, array $queryStringParams = [])
    {
        $params = [];
        $params['index'] = $this->getIndexName();
        
        $resolvedTypes = [];
        foreach ($types as $type) {
            $resolvedTypes[] = $this->resolveTypeName($type);
        }
        
        if (!empty($resolvedTypes)) {
            $params['type'] = implode(',', $resolvedTypes);
        }
        
        $params['body'] = $query;

        if (!empty($queryStringParams)) {
            $params = array_merge($queryStringParams, $params);
        }

        $this->stopwatch('start', 'search');
        $result = $this->client->search($params);
        $this->stopwatch('stop', 'search');

        return $result;
    }
1101504
public function formatCompounds(array $queries) {
        if (!$queries) {
            return '';
        }

        // @codeCoverageIgnoreStart
        if (!method_exists($this, 'buildSelect')) {
            throw new UnsupportedQueryStatementException('Unions require a buildSelect() method');
        }
        // @codeCoverageIgnoreEnd

        $output = [];

        foreach ($queries as $query) {
            $attributes = $query->getAttributes();
            $clause = sprintf($this->getClause($attributes['compound']), trim($this->buildSelect($query), ';'));

            $attributes = $this->formatAttributes($attributes);

            if (empty($attributes['flag'])) {
                $attributes['flag'] = '';
            }

            $output[] = str_replace('{flag}', $attributes['flag'], $clause);
        }

        return implode(' ', $output);
    }
847100
protected function getPages($ids)
    {
        // Check empty set
        if (empty($ids)) {
            return new ArrayList();
        }

        $recordClass = $this->recordClass;

        // Bypass translatable filter
        if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) {
            Translatable::disable_locale_filter();
        }

        // Bypass versioned filter
        if ($recordClass::has_extension(Versioned::class)) {
            // Workaround for get_including_deleted not supporting byIDs filter very well
            // Ensure we select both stage / live records
            $pages = Versioned::get_including_deleted($recordClass)->byIDs($ids);
        } else {
            $pages = DataObject::get($recordClass)->byIDs($ids);
        }

        if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) {
            Translatable::enable_locale_filter();
        }

        return $pages;
    }
629002
protected function _links($query, $links)
    {
        settype($links, 'array');

        foreach ($links as $link) {
            $resource = $link['resource'];
            $description = $link['query']->getRepository()->getDescription();
            $conditions = array();

            foreach ($link['conditions'] as $key => $value) {
                if (is_numeric($key)) {
                    $conditions[] = $value;
                } elseif ($value instanceof AnDomainResourceColumn) {
                    $conditions[] = $key.' = '.(string) $value;
                } else {
                    $conditions[] = $key.' = '.$this->_store->quoteValue($value);
                }
            }

            if ($link['bind_type']) {
                $type = $this->_inheritanceTree($description);
                if (!empty($type) && $type != '%') {
                    $operator = substr($this->_inheritanceTree($description), -1) == '%' ? 'LIKE' : '=';
                    $conditions[] = $link['bind_type']. ' ' . $operator . ' \'' .$this->_inheritanceTree($description).'\'';
                }
            }

            $name = $this->_store->quoteName($link['resource_name']);
            $type = strtoupper($link['type']);
            switch ($type) {
                case 'STRONG' : $type = 'INNER';break;
                case 'WEAK'   : $type = 'LEFT';break;
            }
            //$name    = $this->_store->quoteName($resource->getName());
            $query->join($type, $resource->getName().' AS '.$name, $conditions);

            $this->_links($query, $link->query->link);
        }
    }
869923
public function union($queries, $distinct = false)
    {
        if ($this->_db === null) {
            foreach ($queries as $query) {
                if ($query instanceof self) {
                    $this->_db = $query->_db;
                    break;
                }
            }
        }
        $this->_union = ['type' => 'UNION ' . ($distinct ? 'DISTINCT' : 'ALL'), 'queries' => $queries];

        return $this;
    }