Firestore in Datastore mode API - Class Google::Cloud::Datastore::Filter (v2.8.0)

Reference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::Filter.

Filter

Represents the filter criteria for a datastore query.

Inherits

  • Object

Examples

Run a query with a simple property filter.

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where(filter)

tasks = datastore.run query

Construct a composite filter with a logical OR.

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")
                                         .or("priority", ">=", "4")

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where(filter)

tasks = datastore.run query

Construct a composite filter by combining multiple filters.

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter_1 = Google::Cloud::Datastore::Filter.new("done", "=", "false")
filter_2 = Google::Cloud::Datastore::Filter.new("priority", ">=", "4")
filter = filter_1.or(filter_2)

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where(filter)

tasks = datastore.run query

Methods

#and

def and(name, operator, value)
def and(filter)

Joins two filters with an AND operator.

Overloads
def and(name, operator, value)
Joins the filter with a property filter
Parameters
  • name (String)
  • operator (String)
  • value
def and(filter)
Joins the filter with a Filter object
Parameter
Examples

Join the filter with a property filter

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter = Google::Cloud::Filter.new("done", "=", false)
                              .and("priority", ">=", 4)

Join the filter with a filter object

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter_1 = Google::Cloud::Filter.new("done", "=", false)
filter_2 = Google::Cloud::Filter.new("priority", ">=", 4)

filter = filter_1.and(filter_2)

#initialize

def initialize(name, operator, value) -> Filter

Creates a new Filter.

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

filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")

#or

def or(name, operator, value)
def or(filter)

Joins two filters with an OR operator.

Overloads
def or(name, operator, value)
Joins the filter with a property filter
Parameters
  • name (String) — The property to filter by.
  • operator (String) — The operator to filter by. Defaults to nil.
  • value (Object) —

    The value to compare the property to. Defaults to nil. Possible values are:

    • Integer
    • Float/BigDecimal
    • String
    • Boolean
    • Array
    • Date/Time
    • StringIO
    • Google::Cloud::Datastore::Key
    • Google::Cloud::Datastore::Entity
    • nil
def or(filter)
Joins the filter with a Filter object
Parameter
Examples

Join the filter with a property filter

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter = Google::Cloud::Filter.new("done", "=", false)
                              .or("priority", ">=", 4)

Join the filter with a filter object

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

filter_1 = Google::Cloud::Filter.new("done", "=", false)
filter_2 = Google::Cloud::Filter.new("priority", ">=", 4)

filter = filter_1.or(filter_2)