2.14.1 (latest) 2.14.0 2.13.1 2.12.0 2.11.0 2.10.0 2.9.0 2.8.0 2.7.1 2.6.0 2.5.0 2.4.0 2.3.1 2.2.4 Reference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::GqlQuery.

## GqlQuery

Represents a GQL query.

GQL is a SQL-like language for retrieving entities or keys from
Datastore.

## Inherits

- Object

## Example

```ruby
require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task ORDER BY created ASC"
tasks = datastore.run gql_query
```

## Methods

### #allow_literals

```ruby
def allow_literals() -> Boolean
```
Whether the query may contain literal values. When false, the query
string must not contain any literals and instead must bind all values
using [#named_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#named_bindings= (method)") or [#positional_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)").
**Returns**

- (Boolean) --- `true` if the query may contain literal values

### #allow_literals=

```ruby
def allow_literals=(new_allow_literals)
```
Sets whether the query may contain literal values. When false, the
query string must not contain any literals and instead must bind all
values using [#named_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#named_bindings= (method)") or [#positional_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)").
**Parameter**

- **new_allow_literals** (Boolean) --- `true` if the query may contain literal values
**Example**

```ruby
require "google/cloud/datastore"

gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
                         "WHERE completed = false AND priority = 4"
gql_query.allow_literals = true
```

### #initialize

```ruby
def initialize() -> GqlQuery
```
Returns a new GqlQuery instance.
**Returns**

- ([GqlQuery](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt)) --- a new instance of GqlQuery
**Example**

```ruby
require "google/cloud/datastore"

gql_query = Google::Cloud::Datastore::GqlQuery.new
```

### #named_bindings

```ruby
def named_bindings() -> Hash
```
The named binding values for a query that contains named argument
binding sites that start with `@`.
**Returns**

- (Hash) --- a frozen hash that maps the binding site names in the query string to valid GQL arguments

### #named_bindings=

```ruby
def named_bindings=(new_named_bindings)
```
Sets named binding values for a query that contains named argument
binding sites that start with `@`.
**Parameter**

- **new_named_bindings** (Hash) --- a hash that maps the binding site names in the query string to valid GQL arguments
**Example**

```ruby
require "google/cloud/datastore"

gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
                         "WHERE done = @done " \
                         "AND priority = @priority"
gql_query.named_bindings = {done: false, priority: 4}
```

### #positional_bindings

```ruby
def positional_bindings() -> Array
```
The binding values for a query that contains numbered argument binding
sites that start with `@`.
**Returns**

- (Array) --- a frozen array containing the query arguments in the order of the numbered binding sites in the query string

### #positional_bindings=

```ruby
def positional_bindings=(new_positional_bindings)
```
Sets the binding values for a query that contains numbered argument
binding sites that start with `@`.
**Parameter**

- **new_positional_bindings** (Array) --- query arguments in the order of the numbered binding sites in the query string
**Example**

```ruby
require "google/cloud/datastore"

gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task" \
                         "WHERE completed = @1 AND priority = @2"
gql_query.positional_bindings = [false, 4]
```

### #query_string

```ruby
def query_string() -> String
```
The GQL query string for the query. The string may contain named or
positional argument binding sites that start with `@`. Corresponding
binding values should be set with [#named_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#named_bindings= (method)") or
[#positional_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)").
**Returns**

- (String) --- a GQL statement

### #query_string=

```ruby
def query_string=(new_query_string)
```
Sets the GQL query string for the query. The string may contain named
or positional argument binding sites that start with `@`.
Corresponding binding values should be set with [#named_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#named_bindings= (method)") or
[#positional_bindings=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery.md.txt#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ "Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)").


<br />

See the [GQL
Reference](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
**Parameter**

- **new_query_string** (String) --- a valid GQL statement
**Example**

```ruby
gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
                         "WHERE done = @done " \
                         "AND priority = @priority"
gql_query.named_bindings = {done: false, priority: 4}
```