class Google::Cloud::Firestore::QuerySnapshot

# QuerySnapshot

A query snapshot object is an immutable representation of query results, including chnages from the previous snapshot.

See {Query#listen}.

@example

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Create a query
query = firestore.col(:cities).order(:population, :desc)

listener = query.listen do |snapshot|
  puts "The query snapshot has #{snapshot.docs.count} documents "
  puts "and has #{snapshot.changes.count} changes."
end

# When ready, stop the listen operation and close the stream.
listener.stop

Public Class Methods

from_docs(query, docs, changes, read_at) click to toggle source

@private New QuerySnapshot

# File lib/google/cloud/firestore/query_snapshot.rb, line 110
def self.from_docs query, docs, changes, read_at
  new.tap do |s|
    s.instance_variable_set :@query,   query
    s.instance_variable_set :@docs,    docs
    s.instance_variable_set :@changes, changes
    s.instance_variable_set :@read_at, read_at
  end
end

Public Instance Methods

changes() click to toggle source

The document change objects for the query snapshot.

@return [Array<DocumentChange>] document changes.

# File lib/google/cloud/firestore/query_snapshot.rb, line 73
def changes
  @changes
end
Also aliased as: doc_changes, document_changes
count()
Alias for: size
doc_changes()
Alias for: changes
docs() click to toggle source

The documents in the snapshot.

@return [Array<DocumentSnapshot>] document snapshots.

# File lib/google/cloud/firestore/query_snapshot.rb, line 63
def docs
  @docs
end
Also aliased as: documents
document_changes()
Alias for: changes
documents()
Alias for: docs
empty?() click to toggle source

Determines whether query results exists.

@return [Boolean] Whether query results exists.

# File lib/google/cloud/firestore/query_snapshot.rb, line 94
def empty?
  docs.empty?
end
query() click to toggle source

The query producing this snapshot.

@return [Query] query.

# File lib/google/cloud/firestore/query_snapshot.rb, line 54
def query
  @query
end
read_at() click to toggle source

The time at which the snapshot was read.

@return [Time] The time at which the documents were read.

# File lib/google/cloud/firestore/query_snapshot.rb, line 103
def read_at
  @read_at
end
Also aliased as: read_time
read_time()
Alias for: read_at
size() click to toggle source

Returns the number of documents in this query snapshot.

@return [Integer] The number of documents.

# File lib/google/cloud/firestore/query_snapshot.rb, line 84
def size
  docs.size
end
Also aliased as: count