@param bool $master

@return QueryBuilder
335353
public function force(bool $master = true): self
    {
        if ($master) {
            $this->node = Pool::MASTER;
        }

        return $this;
    }
874140
public function getQueryBuilder($entity): QueryBuilderInterface
    {
        $metaInformation = $this->metaInformationFactory->loadInformation($entity);

        return new QueryBuilder($this, $metaInformation);
    }
347205
public function andIf($master = null)
    {
        if ($this->logicalOperator == "or") {
            throw new Exception("ValidationLogicCriteria: Cannot declare a logical operator more than once. (Specified andIf() after calling orIf()). Use a nested ValidationLogicCriteriaSet to combine conjunctive and disjuctive logic.");
        }
        if ($master) {
            $this->master = $master;
        }
        $this->logicalOperator = "and";
        return $this;
    }
1216436
public function readMaster($all = false)
    {
        $table = $all ? '*' : $this->getTable();

        static::$readMaster[$table] = true;

        return $this;
    }
258287
protected function getQueryBuilderForDemand(): QueryBuilder
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder
            ->select('*')
            ->from('sys_redirect')
            ->orderBy('source_host')
            ->addOrderBy('source_path');

        $constraints = [];
        if ($this->demand->hasSourceHost()) {
            $constraints[] =$queryBuilder->expr()->eq(
                'source_host',
                $queryBuilder->createNamedParameter($this->demand->getSourceHost(), \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasSourcePath()) {
            $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getSourcePath()) . '%';
            $constraints[] = $queryBuilder->expr()->like(
                'source_path',
                $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasTarget()) {
            $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getTarget()) . '%';
            $constraints[] = $queryBuilder->expr()->like(
                'target',
                $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasStatusCode()) {
            $constraints[] =$queryBuilder->expr()->eq(
                'target_statuscode',
                $queryBuilder->createNamedParameter($this->demand->getStatusCode(), \PDO::PARAM_INT)
            );
        }

        if (!empty($constraints)) {
            $queryBuilder->where(...$constraints);
        }
        return $queryBuilder;
    }
363574
public function runMongoQuery($tableName, $condition = [], $queryOptions = [], $useMaster = false)
    {
        Cml::$debug && $this->debugLogSql('Query', $tableName, $condition, $queryOptions);

        $this->reset();
        $db = $useMaster ?
            $this->getMaster()->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY_PREFERRED))
            : $this->getSlave()->selectServer(new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED));
        $cursor = $db->executeQuery($this->getDbName() . ".{$tableName}", new Query($condition, $queryOptions));
        $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
        $result = [];
        foreach ($cursor as $collection) {
            $result[] = $collection;
        }
        return $result;
    }
995613
protected function getSubQuery(
        Contracts\QueryEntity $meta,
        Builder $query = null,
        array $conditions = [],
        $boolean = 'and'
    ): Builder
    {
        $model = $meta->getModel();
        $query = $query ?? $model->newQuery();

        foreach ($conditions as $condition) {
            $this->buildCondition($meta, $query, $condition, $boolean);
        }
        return $query;
    }
516576
protected function initConnect($master = true)
    {
        if (!empty($this->config['deploy'])) {
            // 采用分布式数据库
            if ($master) {
                if (!$this->linkWrite) {
                    $this->linkWrite = $this->multiConnect(true);
                }

                $this->mongo = $this->linkWrite;
            } else {
                if (!$this->linkRead) {
                    $this->linkRead = $this->multiConnect(false);
                }

                $this->mongo = $this->linkRead;
            }
        } elseif (!$this->mongo) {
            // 默认单数据库
            $this->mongo = $this->connect();
        }
    }
83804
protected function newBaseQueryBuilder()
    {
        $connection = $this->getConnection();

        return new DatabaseEncryptionQueryBuilder(
            $connection, $connection->getQueryGrammar(), $connection->getPostProcessor()
        );
    }
641334
public function queryBuilder()
    {
        if (!$this->queryBuilder) {
            $this->queryBuilder = $this->grid->model()->getQueryBuilder();
        }

        return $this->queryBuilder;
    }
537033
public static function queryMetas()
	{
		$model = new static;
		
		$conn = $model->getConnection();
		$query = new QueryBuilder(
			$conn,
			$conn->getQueryGrammar(),
			$conn->getPostProcessor()
		);
		
		$query->setModel($model);
		
		return $query;
	}
262372
public function getQueryBuilder(): QueryBuilder
    {
        if (!$this->queryBuilder) {
            $this->queryBuilder = $this->repository->createQueryBuilder($this->getAlias());
            if ($this->getConfiguration()->getOption('enforce_family_condition', true)) {
                $familyParam = uniqid('family', false);
                $this->queryBuilder
                    ->andWhere("{$this->getAlias()}.family = :{$familyParam}")
                    ->setParameter($familyParam, $this->getFamily()->getCode());
            }
        }

        return $this->queryBuilder;
    }
1224044
private function slaveQueryBuilder()
    {
        /** @var Connection $connection */
        $connection = $this->getEntityManager()->getConnection();
        if ($connection instanceof MasterSlaveConnection) {
            // Prefer a slave connection if available.
            $connection->connect('slave');
        }

        return new QueryBuilder($connection);
    }
566543
private function getQuerySelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT q.*, qt.*')
            ->from('ngbm_collection_query', 'q')
            ->innerJoin(
                'q',
                'ngbm_collection_query_translation',
                'qt',
                $query->expr()->andX(
                    $query->expr()->eq('qt.query_id', 'q.id'),
                    $query->expr()->eq('qt.status', 'q.status')
                )
            );

        return $query;
    }
356842
public function requireIndexes($bool = true)
    {
        if (!$this->isQueryOrScan()) {
            //TODO: exception
        }

        if ($bool) {
            $this->queryClass = Query::class;
        } else {
            $this->queryClass = Scan::class;
        }

        return $this;
    }
461877
protected function _endChildSubQuery($tool, array $subQuery, $bool, array $params = []) {
        $this->addBool([$tool => $subQuery], $bool, true, $params);
        return $this;
    }
749299
public function orIf($master = null)
    {
        if ($this->logicalOperator == "and") {
            throw new Exception("ValidationLogicCriteria: Cannot declare a logical operator more than once. (Specified orIf() after calling andIf()). Use a nested ValidationLogicCriteriaSet to combine conjunctive and disjuctive logic.");
        }
        if ($master) {
            $this->master = $master;
        }
        $this->logicalOperator = "or";
        return $this;
    }