Execute the findOne query.

@see Collection::findOne()
@param array $query
@param array $fields
@return array|null
321126
protected function doFindOne(array $query, array $fields)
    {
        $riakCollection = $this->riakCollection;
        return $this->retry(function() use ($riakCollection, $query, $fields) {
            return $riakCollection->findOne($query, $fields);
        });
    }
277808
public function find($criteria = [], array $fields = []) {
		$criteriaNormalized = $this->normalizeCriteria($criteria);
		
		$mongoCursor = $this->getAdapter()->find(
			$this->getTableName(),
			$criteriaNormalized,
			$fields
		);
		
		if ($criteria instanceof Criteria) {
			$this->applyCriteriaToCursor($criteria, $mongoCursor);
		}
		
		return $this->createResultset($mongoCursor);
	}
223458
public static function first($query = null, $fields = null, $last = false)
    {
        static::applySchema();

        $key = static::getPrimaryKey();
        $table = static::getTable();
        $writer = static::getDatabase()->getWriter();

        if (!$query && !$fields) {
            $fields = '*';
        } elseif (is_string($query) && !$fields) {
            $fields = explode(',', $query);
            $query = null;
        }

        $order = '';
        if (isset($query['order'])) {
            $order = 'ORDER BY '.$query['order'];
            unset($query['order']);
        } else {
            $order = 'ORDER BY '.'`'.$key.'`'.' '.($last ? 'DESC' : 'ASC');
        }

        if (!$fields && isset($query['fields'])) {
            $fields = $query['fields'];
            unset($query['fields']);
        }

        if (!$fields) {
            $fields = '*';
        }

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

        $valueArray = [];
        if (count($query) > 0) {
            $schema = static::getSchemaFields();
            foreach ($schema as $field) {
                if (!isset($query[$field])) {
                    continue;
                }
                $token = ':'.$field;
                $whereArray[] = "`{$field}` = {$token}";
                $valueArray[$token] = $query[$field];
            }
        }

        $join = '';
        $class = static::getClassName();
        $selectFields = $writer->selectFields($fields, $class, $join);
        $where = $writer->whereByArray($whereArray);
        $sql = "SELECT {$selectFields} FROM `{$table}` AS {$class} {$where} {$order} LIMIT 1";

        $result = static::fetch(
            $sql,
            $valueArray,
            true,
            is_array($fields) && count($fields) == 1,
            $fields == '*'
        );

        return $result;
    }
50969
public function findAll(array $query = [])
    {
        $data = $this->client->get(Inflector::pluralize($this->getResourceName()), $query);

        return $this->createMany(reset($data));
    }
566631
public function findMany($query, array $data = null){
        $stmt = $this->executeQuery($query, $data);
        
        return($stmt->fetchAll(\PDO::FETCH_ASSOC));
    }
1169731
public function findAllByQuery($query, array $params = array()) {
		//Not using the parent findAllByQuery() implementation, becaus
		//it performs one-by-one EAV fetching, which is very bad for performance.
		//Instead, we find all main records with 1 query. And then fine all EAV entries (for all),
		//with a single additional query (instead of one per main record).

		$records = array();
		$recordIds = array();
		foreach ($this->db->fetchAll($query, $params) as $data) {
			$records[] = $data;
			$recordIds[] = $data['_id'];
		}

		$dataPerNamespaceFlattened = $this->pullEavDataForAll($recordIds);

		$results = array();
		foreach ($records as $data) {
			$data['__eav_data__'] = $dataPerNamespaceFlattened[$data['_id']];
			$results[] = $this->loadModel($data);
		}

		return $results;
	}
1095699
public function selectInsert(Query $query, $fields, $table)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成SQL语句
        $table = $this->parseSqlTable($table);

        $sql = $this->builder->selectInsert($query, $fields, $table);

        $bind = $query->getBind();

        if (!empty($options['fetch_sql'])) {
            // 获取实际执行的SQL语句
            return $this->getRealSql($sql, $bind);
        }
        // 执行操作
        return $this->execute($sql, $bind, $query);
    }
652589
public static function find(array $query)
    {
        $employees = Client::get("employee", $query);
        return array_map(function ($data) { return new self($data); }, $employees);
    }
1340562
public function findByQuery($query)
    {
        $qb = $this->createQueryBuilder();
        $parts  = explode(' ', trim($query));
        
        foreach ($parts as $q) {
            $regex = new \MongoRegex('/^' . $query . '/i');
            $qb->addOr($qb->expr()->field('info.firstName')->equals($regex));
            $qb->addOr($qb->expr()->field('info.lastName')->equals($regex));
            $qb->addOr($qb->expr()->field('info.email')->equals($regex));
        }
        $qb->sort(array('info.lastName' => 1))
           ->sort(array('info.email' => 1));
        
        return $qb->getQuery()->execute();
    }
335917
public function setFieldQuery(string $field, string $query): self
    {
        return $this->setFieldParam($field, 'query', $query);
    }
1265340
public function parseFql($fieldName, $query)
    {
        // 
        if(is_string($query)) {
            // 
            $lexer = $this->createLexer((string)$query);
            
            $field = new Expr\FieldIdentifier($fieldName);
            try {
                $expr = $this->doParseExpression($lexer, $field);
            } catch(\Exception $ex) {
                throw new ParserException(sprintf('Failed to parse qeury "%s"', $query), 0, $ex);
            }

            if(!$lexer->isEol()) {
                throw new ParserException(sprintf('Invalid query "%s"', $lexer->remain()));
            }

            return $expr;
        } else if(is_array($query)) {
            $exprs = array();
            foreach($query as $q) {
                $exprs[] = $this->parseFql($fieldName, $q);
            }

            //return new Expr\AndX($exprs);
            return new Expr\LogicalExpression($exprs, Expr\LogicalExpression::TYPE_AND);
        } else {
            return new Expr\ComparisonExpression($field, $query, Expr\ComparisonExpression::EQ);
        }

        throw new ParserException('Invalid Fql query.');
    }
934500
public function findOne(array $query = [], array $fields = [])
    {
        if ($this->eventManager->hasListeners(Events::preFindOne)) {
            $findEventArgs = new FindEventArgs($this, $query, $fields);
            $this->eventManager->dispatchEvent(Events::preFindOne, $findEventArgs);
            $query = $findEventArgs->getQuery();
            $fields = $findEventArgs->getFields();
        }

        $result = $this->doFindOne($query, $fields);

        if ($this->eventManager->hasListeners(Events::postFindOne)) {
            $eventArgs = new MutableEventArgs($this, $result);
            $this->eventManager->dispatchEvent(Events::postFindOne, $eventArgs);
            $result = $eventArgs->getData();
        }

        return $result;
    }
36828
public static function find($fields = '*')
    {
        $entity = new static();
        if ($fields == '*') {
            $fields = $entity->getTableName() .'.*';
        }
        Entity\Manager::getInstance()->get($entity)->refreshRelations();
        $select = new \Slick\Orm\Sql\Select($entity, $fields);
        return $select;
    }
791816
public function whereNull($fields)
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $exp = $this->newExpr();

        foreach ($fields as $field) {
            $exp->isNull($field);
        }

        return $this->where($exp);
    }
1353591
public function findWhereIn($field, array $values, $columns = ['*'])
    {
        return parent::findWhereIn(
            $this->getColumnName($field),
            $values,
            $this->getColumnsNames($columns)
        );
    }
260480
public final function findOne($id, $fields = '*') {
        if (is_array($id)) {
            $where = $id;
        } else {
            $idf   = $this->primaryKey;
            $where = [$idf => $id];
        }
        if (is_array($fields)) {
            $sql = $this->select(...$fields);
        } else {
            $sql = $this->select($fields);
        }
        $sql->where($where)->limit(0, 1);

        return $sql;
    }
1059137
public function find($query, $fields = ['username', 'email']): UserInterface
    {
        $fields = (array)$fields;

        $account_dir = Grav::instance()['locator']->findResource('account://');
        $files = $account_dir ? array_diff(scandir($account_dir), ['.', '..']) : [];

        // Try with username first, you never know!
        if (in_array('username', $fields, true)) {
            $user = $this->load($query);
            unset($fields[array_search('username', $fields, true)]);
        } else {
            $user = $this->load('');
        }

        // If not found, try the fields
        if (!$user->exists()) {
            foreach ($files as $file) {
                if (Utils::endsWith($file, YAML_EXT)) {
                    $find_user = $this->load(trim(pathinfo($file, PATHINFO_FILENAME)));
                    foreach ($fields as $field) {
                        if ($find_user[$field] === $query) {
                            return $find_user;
                        }
                    }
                }
            }
        }
        return $user;
    }