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.
def and(name, operator, value)
- name (String)
- operator (String)
- value
def and(filter)
- filter (Filter)
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.
- (Filter) — a new instance of Filter
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.
def or(name, operator, value)
- 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)
- flter (Filter)
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)