Class: Google::Cloud::Firestore::QuerySnapshot

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

Overview

QuerySnapshot

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

See Google::Cloud::Firestore::Query#listen.

Examples:

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

Instance Method Summary collapse

Instance Method Details

#changesArray<DocumentChange> Also known as: doc_changes, document_changes

The document change objects for the query snapshot.

Returns:



73
74
75
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 73

def changes
  @changes
end

#docsArray<DocumentSnapshot> Also known as: documents

The documents in the snapshot.

Returns:



63
64
65
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 63

def docs
  @docs
end

#empty?Boolean

Determines whether query results exists.

Returns:

  • (Boolean)

    Whether query results exists.



94
95
96
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 94

def empty?
  docs.empty?
end

#queryQuery

The query producing this snapshot.

Returns:



54
55
56
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 54

def query
  @query
end

#read_atTime Also known as: read_time

The time at which the snapshot was read.

Returns:

  • (Time)

    The time at which the documents were read.



103
104
105
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 103

def read_at
  @read_at
end

#sizeInteger Also known as: count

Returns the number of documents in this query snapshot.

Returns:

  • (Integer)

    The number of documents.



84
85
86
# File 'lib/google/cloud/firestore/query_snapshot.rb', line 84

def size
  docs.size
end