Firestore in Datastore mode API - Class Google::Cloud::Datastore::GqlQuery (v2.10.0)

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

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

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= or #positional_bindings=.

Returns
  • (Boolean) — true if the query may contain literal values

#allow_literals=

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= or #positional_bindings=.

Parameter
  • new_allow_literals (Boolean) — true if the query may contain literal values
Example
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

def initialize() -> GqlQuery

Returns a new GqlQuery instance.

Returns
  • (GqlQuery) — a new instance of GqlQuery
Example
require "google/cloud/datastore"

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

#named_bindings

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=

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
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

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=

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
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

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= or #positional_bindings=.

Returns
  • (String) — a GQL statement

#query_string=

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= or #positional_bindings=.

See the GQL Reference.

Parameter
  • new_query_string (String) — a valid GQL statement
Example
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}