PHP Класс Google\Cloud\Datastore\Query\GqlQuery
By default, parameters MUST be bound using named or positional bindings.
Literals are disabled by default, and must be enabled by setting
$options['allowLiterals'] to
true. As with any SQL-style language, using
parameter binding is highly recommended.
Idiomatic usage is via {@see \Google\Cloud\Datastore\DatastoreClient::gqlQuery()}.
Example:
use Google\Cloud\ServiceBuilder;
$cloud = new ServiceBuilder();
$datastore = $cloud->datastore();
$query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @companyName', [
'bindings' => [
'companyName' => 'Google'
]
]);
$res = $datastore->runQuery($query);
foreach ($res as $company) {
echo $company['companyName']; // Google
}
Positional binding is also supported
$query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @1', [
'bindings' => [
'Google'
]
]);
While not recommended, you can use literals in your query string:
$query = $datastore->gqlQuery("SELECT * FROM Companies WHERE companyName = 'Google'", [
'allowLiterals' => true
]);
Показать файл
Открыть проект
Примеры использования класса
Открытые методы
Приватные методы
Описание методов
__construct()
публичный Метод
public __construct ( EntityMapper $entityMapper, string $query, array $options = [] ) |
$entityMapper |
Google\Cloud\Datastore\EntityMapper |
An instance of EntityMapper |
$query |
string |
The GQL Query string. |
$options |
array |
[optional] {
Configuration Options
@type bool $allowLiterals Whether literal values will be allowed in
the query string. Parameter binding is strongly encouraged over
literals. **Defaults to** `false`.
@type array $bindings An array of values to bind to the query string.
Queries using Named Bindings should provide a key/value set,
while queries using Positional Bindings must provide a simple
array.
Applications with no need for multitenancy should not set this value.
} |
canPaginate()
публичный Метод
Indicate that this type does not support automatic pagination.
jsonSerialize()
публичный Метод
Define the json respresentation of the object.
queryKey()
публичный Метод
Return the query_type union field name.
queryObject()
публичный Метод
This method is used internally to run queries and is not intended for use
outside the internal library API
Fulfill the interface, but cursors are handled inside the query string.