Class: Google::Cloud::Firestore::QueryPartition

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

Overview

QueryPartition

Represents a split point that can be used in a query as a starting and/or end point for the query results.

The cursors returned by #start_at and #end_before can only be used in a query that matches the constraint of the query that produced this partition.

See CollectionGroup#partitions and Query.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

col_group = firestore.col_group "cities"

partitions = col_group.partitions 3

queries = partitions.map(&:to_query)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_beforeArray<Object>? (readonly)

The cursor values that define the first result after this partition, or nil if this is the last partition. Returns an array of values that represent a position, in the order they appear in the order by clause of the query. Can contain fewer values than specified in the order by clause. Will be used in the query returned by #to_query.

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/google/cloud/firestore/query_partition.rb', line 53

class QueryPartition
  attr_reader :start_at
  attr_reader :end_before

  ##
  # @private New QueryPartition from query and Cursor
  def initialize query, start_at, end_before
    @query = query
    @start_at = start_at
    @end_before = end_before
  end

  ##
  # Creates a new query that only returns the documents for this partition, using the cursor values from
  # {#start_at} and {#end_before}.
  #
  # @return [Query] The query for the partition.
  #
  def to_query
    base_query = @query
    base_query = base_query.start_at start_at if start_at
    base_query = base_query.end_before end_before if end_before
    base_query
  end
end

#start_atArray<Object>? (readonly)

The cursor values that define the first result for this partition, or nil if this is the first partition. Returns an array of values that represent a position, in the order they appear in the order by clause of the query. Can contain fewer values than specified in the order by clause. Will be used in the query returned by #to_query.

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/google/cloud/firestore/query_partition.rb', line 53

class QueryPartition
  attr_reader :start_at
  attr_reader :end_before

  ##
  # @private New QueryPartition from query and Cursor
  def initialize query, start_at, end_before
    @query = query
    @start_at = start_at
    @end_before = end_before
  end

  ##
  # Creates a new query that only returns the documents for this partition, using the cursor values from
  # {#start_at} and {#end_before}.
  #
  # @return [Query] The query for the partition.
  #
  def to_query
    base_query = @query
    base_query = base_query.start_at start_at if start_at
    base_query = base_query.end_before end_before if end_before
    base_query
  end
end

Instance Method Details

#to_queryQuery

Creates a new query that only returns the documents for this partition, using the cursor values from #start_at and #end_before.

Returns:

  • (Query)

    The query for the partition.



71
72
73
74
75
76
# File 'lib/google/cloud/firestore/query_partition.rb', line 71

def to_query
  base_query = @query
  base_query = base_query.start_at start_at if start_at
  base_query = base_query.end_before end_before if end_before
  base_query
end