PHP Class 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
]);
显示文件
Open project: GoogleCloudPlatform/gcloud-php
Class Usage Examples
Public Methods
Private Methods
Method Details
__construct()
public method
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()
public method
Indicate that this type does not support automatic pagination.
jsonSerialize()
public method
Define the json respresentation of the object.
Return the query_type union field name.
queryObject()
public method
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.