diff options
author | rsgowman <rgowman@google.com> | 2018-04-18 10:30:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-18 10:30:37 -0400 |
commit | a5b3185ed372fc16b5430c230c197e3dbd34f953 (patch) | |
tree | 8f77610cf27ee35f5cccad825b6a33e74d7be8ef /Firestore/Example/SwiftBuildTest/main.swift | |
parent | 6a39c71be83f589550c7dfa3c6d89d8b6145887c (diff) |
Add GetOptions for controlling offline get behaviour (#655)
Add option to allow the user to control where DocumentReference.getDocument() and CollectionReference.getDocuments() fetches from. By default, it fetches from the server (if possible) and falls back to the local cache. It's now possible to alternatively fetch from the local cache only, or to fetch from the server only (though in the server only case, latency compensation is still enabled).
Diffstat (limited to 'Firestore/Example/SwiftBuildTest/main.swift')
-rw-r--r-- | Firestore/Example/SwiftBuildTest/main.swift | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index 00839c4..f61da2b 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -32,8 +32,10 @@ func main() { addDocument(to: collectionRef) readDocument(at: documentRef) + readDocumentWithSource(at: documentRef) readDocuments(matching: query) + readDocumentsWithSource(matching: query) listenToDocument(at: documentRef) @@ -230,6 +232,15 @@ func readDocument(at docRef: DocumentReference) { } } +func readDocumentWithSource(at docRef: DocumentReference) { + docRef.getDocument(source: FirestoreSource.default) { document, error in + } + docRef.getDocument(source: .server) { document, error in + } + docRef.getDocument(source: FirestoreSource.cache) { document, error in + } +} + func readDocuments(matching query: Query) { query.getDocuments { querySnapshot, error in // TODO(mikelehen): Figure out how to make "for..in" syntax work @@ -240,6 +251,15 @@ func readDocuments(matching query: Query) { } } +func readDocumentsWithSource(matching query: Query) { + query.getDocuments(source: FirestoreSource.default) { querySnapshot, error in + } + query.getDocuments(source: .server) { querySnapshot, error in + } + query.getDocuments(source: FirestoreSource.cache) { querySnapshot, error in + } +} + func listenToDocument(at docRef: DocumentReference) { let listener = docRef.addSnapshotListener { document, error in if let error = error { |