Class: Google::Cloud::Firestore::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/firestore/filter.rb

Overview

Represents the filter for structured query.

Instance Method Summary collapse

Constructor Details

#initialize(field, operator, value) ⇒ Google::Cloud::Firestore::Filter

Create a Filter object.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Create a Filter
Google::Cloud::Firestore::Filter.new(:population, :>=, 1000000)

Parameters:

  • field (FieldPath, String, Symbol)

    A field path to filter results with. If a Google::Cloud::Firestore::FieldPath object is not provided then the field will be treated as a dotted string, meaning the string represents individual fields joined by ".". Fields containing ~, *, /, [, ], and . cannot be in a dotted string, and should provided using a Google::Cloud::Firestore::FieldPath object instead.

  • operator (String, Symbol)

    The operation to compare the field to. Acceptable values include:

    • less than: <, lt
    • less than or equal: <=, lte
    • greater than: >, gt
    • greater than or equal: >=, gte
    • equal: =, ==, eq, eql, is
    • not equal: !=
    • in: in
    • not in: not-in, not_in
    • array contains: array-contains, array_contains
  • 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


76
77
78
# File 'lib/google/cloud/firestore/filter.rb', line 76

def initialize field, operator, value
  @filter = create_filter field, operator, value
end

Instance Method Details

#where(filter) ⇒ Filter #where(field, operator, value) ⇒ Filter

Joins filter using AND operator.

@param filter [::Google::Cloud::Firestore::Filter]

Examples:

Pass a Filter type object in argument

require "google/cloud/firestore"

filter_1 = Google::Cloud::Firestore.Firestore.new(:population, :>=, 1000000)
filter_2 = Google::Cloud::Firestore.Firestore.new("done", "=", "false")

filter = filter_1.and(filter_2)

Pass filter conditions in the argument

require "google/cloud/firestore"

filter_1 = Google::Cloud::Firestore.Firestore.new(:population, :>=, 1000000)

filter = filter_1.and("done", "=", "false")

Overloads:

  • #where(filter) ⇒ Filter

    Pass Firestore::Filter to where via field_or_filter argument.

  • #where(field, operator, value) ⇒ Filter

    Pass arguments to where via positional arguments.

    Parameters:

    • field (FieldPath, String, Symbol)

      A field path to filter results with. If a Google::Cloud::Firestore::FieldPath object is not provided then the field will be treated as a dotted string, meaning the string represents individual fields joined by ".". Fields containing ~, *, /, [, ], and . cannot be in a dotted string, and should provided using a Google::Cloud::Firestore::FieldPath object instead.

    • operator (String, Symbol)

      The operation to compare the field to. Acceptable values include:

      • less than: <, lt
      • less than or equal: <=, lte
      • greater than: >, gt
      • greater than or equal: >=, gte
      • equal: =, ==, eq, eql, is
      • not equal: !=
      • in: in
      • not in: not-in, not_in
      • array contains: array-contains, array_contains
    • 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

Returns:

  • (Filter)

    New Filter object.



141
142
143
# File 'lib/google/cloud/firestore/filter.rb', line 141

def and filter_or_field = nil, operator = nil, value = nil
  combine_filters composite_filter_and, filter_or_field, operator, value
end

#where(filter) ⇒ Filter #where(field, operator, value) ⇒ Filter

Joins filter using OR operator.

@param filter [::Google::Cloud::Firestore::Filter]

Examples:

Pass a Filter type object in argument

require "google/cloud/firestore"

filter_1 = Google::Cloud::Firestore.Firestore.new(:population, :>=, 1000000)
filter_2 = Google::Cloud::Firestore.Firestore.new("done", "=", "false")

filter = filter_1.or(filter_2)

Pass filter conditions in the argument

require "google/cloud/firestore"

filter_1 = Google::Cloud::Firestore.Firestore.new(:population, :>=, 1000000)

filter = filter_1.or("done", "=", "false")

Overloads:

  • #where(filter) ⇒ Filter

    Pass Firestore::Filter to where via field_or_filter argument.

  • #where(field, operator, value) ⇒ Filter

    Pass arguments to where via positional arguments.

    Parameters:

    • field (FieldPath, String, Symbol)

      A field path to filter results with. If a Google::Cloud::Firestore::FieldPath object is not provided then the field will be treated as a dotted string, meaning the string represents individual fields joined by ".". Fields containing ~, *, /, [, ], and . cannot be in a dotted string, and should provided using a Google::Cloud::Firestore::FieldPath object instead.

    • operator (String, Symbol)

      The operation to compare the field to. Acceptable values include:

      • less than: <, lt
      • less than or equal: <=, lte
      • greater than: >, gt
      • greater than or equal: >=, gte
      • equal: =, ==, eq, eql, is
      • not equal: !=
      • in: in
      • not in: not-in, not_in
      • array contains: array-contains, array_contains
    • 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

Returns:

  • (Filter)

    New Filter object.



206
207
208
# File 'lib/google/cloud/firestore/filter.rb', line 206

def or filter_or_field = nil, operator = nil, value = nil
  combine_filters composite_filter_or, filter_or_field, operator, value
end