@param Query $query
@param null  $recordClass

@return mixed
511099
public function prepareQuery(Query $query, $recordClass = null)
    {
        $this->recordClass = $recordClass;
        $sql = $query->buildSQL();
        $binds = $query->buildBinds();
        $prepare = $this->getConnection()->prepare($sql);

        if (!$prepare) {
            throw new Exception('Cannot prepare statement');
        }

        /**
         * Trigger query.prepared event.
         */
        trigger(Query::class . '.prepared', ['sql' => $sql, 'binds' => $binds]);
        trigger(Query::class . '.preparedRepo', ['sql' => $sql, 'binds' => $binds, 'repo' => $this->getName()]);

        $this->bindBinds($prepare, $binds);

        $prepare->setFetchMode(\PDO::FETCH_ASSOC);

        return $prepare;
    }
689381
protected function formatQuery(Query $query)
    {
        // handle numeric where, from 2 to ['id'=>2]
        if (!$query->formatted() && $where = $query->get('where')) {
            $table = static::getFirstTable($query['table']);
            $atable  = static::getFirstTableAlias($query['table']);
            $model  = static::getQueryModel();
            $pk     = isset($model['primary_key']) ? $model['primary_key'] : null;
            $spk    = $atable . '.' . $pk;
            foreach ($where as $k=>$v) {
                if (is_numeric($k)) {
                    if (is_numeric($v)) {
                        if (!$pk) {
                            throw new Exception('pk is not set:' . $table);
                        }
                        $where[$k] = [$spk => $v];
                    } elseif (is_array($v)) {
                        foreach ($v as $k2=>$v2) {
                            if (is_numeric($k2) && is_numeric($v2)) {
                                if (!$pk) {
                                    throw new Exception('pk is not set:' . $table);
                                }
                                $where[$k][$k2] = [$spk => $v2];
                            }
                        }
                    }
                }
            }
            
            $query->setRaw('where', $where);
        }
        
        return $query;
    }
917301
public function get($class=null)
	{
		$class = $this->get_class($class);

		if (isset($this->reflections[$class]))
			return $this->reflections[$class];

		throw new ActiveRecordException("Class not found: $class");
	}
1225415
public function getPlanRecords(PlanRecordQuery $query = null)
    {
        $url = $this->accountsEndpoint . 'records/plan';
        $options = [];

        if ($query) {
            $options['query'] = $query->getParams();
        }

        return PlanRecord::getCollection($url, 0, $options, $this->connector->getClient());
    }
29066
public function queriedDelete(Query $query)
    {
        $identifier = $this->getIdentifier();
        $queryResult = $this->query($query);
        $deletedIds = [];

        foreach ($queryResult as $record) {
            try {
                $deletedRecord = $this->delete($record[$identifier]);
                $deletedIds[] = $deletedRecord[$identifier];
            } catch (\Throwable $e) {
                // TODO: need to log record that was not deleted
                continue;
            }
        }

        return $deletedIds;
    }
1209739
public function getRecord($recordId, $dataDimensions = null)
    {

        if ($dataDimensions == null) {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        if ($this->isSingleContentRecordCaching()) {
            $cacheKey = $this->createCacheKey('record', [$this->getCurrentContentTypeName(), $recordId],
                                              $dataDimensions);

            $data = $this->getCacheProvider()->fetch($cacheKey);

            if ($data) {

                $data = json_decode($data, true);
                $recordFactory = $this->getRecordFactory();
                $record        = $recordFactory->createRecordFromJSON($this->getCurrentContentTypeDefinition(), $data);

                $record->setLanguage($dataDimensions->getLanguage());
                $record->setWorkspace($dataDimensions->getWorkspace());
                $record->setViewName($dataDimensions->getViewName());

                $record->setRepository($this);

                return $record;
            }

            $record = parent::getRecord($recordId, $dataDimensions);

            if ($record) {
                $data = json_encode($record);

                $this->getCacheProvider()->save($cacheKey, $data, $this->singleContentRecordCaching);
            }

            return $record;
        }

        return parent::getRecord($recordId, $dataDimensions);
    }
659406
protected function performJoin($query = null)
    {
        $query = $query ?: $this->query;

        // We need to join to the intermediate table on the related model's primary
        // key column with the intermediate table's foreign key for the related
        // model instance. Then we can set the "where" for the parent models.
        $baseTable = $this->related->getTable();

        $key = $baseTable.'.'.$this->relatedKey;

        $query->join($this->table, $key, '=', $this->getQualifiedRelatedPivotKeyName());

        return $this;
    }
346635
final public function page($pageNumber, $recordsPerPage = null)
    {
        $recordsPerPage = $recordsPerPage ?? $this->recordsPerPage;

        $this->getQuery()->limit(((int)$pageNumber) * $recordsPerPage, $recordsPerPage);
        $this->pagedQuery = true;

        return $this;
    }
694091
protected function exec($query)
    {
        try {
            Connect::getConn()->exec($query);
        } catch (Exception $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response["code"] = $e->getCode();

            return static::terminate(static::$response);
        }
        return null;
    }
1302544
public function queryClass($statement, $classname, $params = array(), $ctorargs = array()) {
        $start = microtime(true);
        $q = $statement . '';
        if (is_a($statement, ModelCondition::className())){
            foreach ($statement->getJoinParams() as $k=>$v){
                $params[$k] = $v;
            }
        }
        $statement = $this->prepare($q);
        try {
            $statement->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $q,
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $objects = array();
        while ($ob = $statement->fetchObject($classname, $ctorargs)) {
            $objects[] = $ob;
        }
        $this->debug($q, array(
            'params' => $params,
            'intoClass' => $classname,
            'controllerArguments' => $ctorargs,
            'rows' => count($objects),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $objects;
    }
98032
public function handle( Record $record )
    {
        if (is_null( $this->aggregateRecord )) {
            $this->setAggregateRecord( $record ); // first record

            return null;
        }

        if ($this->aggregateRecord->pushRecord( $record )) {
            return null;
        }

        return $this->setAggregateRecord( $record );
    }
759297
public function selectOne( $query, $bindings = [] )
	{
		$records = $this->select( $query, $bindings );

		return count( $records ) > 0 ? reset( $records ) : null;
	}
679888
protected function match(RecordInterface $record, $query): bool
    {
        if ($record === $query) {
            //Strict search
            return true;
        }

        //Primary key comparision
        if (is_scalar($query) && $record->primaryKey() == $query) {
            return true;
        }

        //Record based comparision
        if ($query instanceof RecordInterface) {
            //Matched by PK (assuming both same class)
            if (!empty($query->primaryKey()) && $query->primaryKey() == $record->primaryKey()) {
                return true;
            }

            //Matched by content (this is a bit tricky!)
            if ($record->packValue() == $query->packValue()) {
                return true;
            }

            return false;
        }

        //Field intersection
        if (is_array($query) && array_intersect_assoc($record->packValue(), $query) == $query) {
            return true;
        }

        return false;
    }
1065982
public function process(QueryInterface $query)
    {
        if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_DATABASES) {
            return null;
        }

        $command = new GetKeyspaces();
        /* @var $vtCtldResult GetKeyspacesResult */
        $vtCtldResult = $this->client->executeCommand($command);

        return new Databases($vtCtldResult);
    }
705270
public function search($query)
    {
        $classes = $this->getClassMetadata();
        return $this->_sm->getUnitOfWork()->loadCollection($classes, $query);
    }
134501
public function parse($query=null)
    {
        $this->checkQuery($query);
        
        return $this->getDb()->setQuery($this->getQuery())->parse();
    }
331144
public function queriedUpdate($record, Query $query)
    {
        $identifier = $this->getIdentifier();

        if (isset($record[$identifier])) {
            throw new DataStoreException('Primary key is not allowed in record for queried update');
        }

        $forUpdateRecords = $this->query($query);
        $updatedIds = [];

        foreach ($forUpdateRecords as $forUpdateRecord) {
            try {
                $updatedRecord = $this->update(array_merge($record, [$identifier => $forUpdateRecord[$identifier]]));
                $updatedIds[] = $updatedRecord[$identifier];
            } catch (\Throwable $e) {
                // TODO: log failed queried updated record
                continue;
            }
        }

        return $updatedIds;
    }