Skip to content

Convenience functions for using Firebase Firestore with Swift Concurrency (async/await).

License

Notifications You must be signed in to change notification settings

SwiftfulThinking/SwiftfulFirestore

Repository files navigation

SwiftfulFirestore 🏎️

Convenience functions for using Firebase Firestore with Swift Concurrency.

Most functions are an extension of CollectionReference.

Usage

Import the package to your project.

Import the package to your file.

import SwiftfulFirestore

Conform to StringIdentifiable (optional).

struct Movie: Codable, StringIdentifiable {
    let id = UUID().uuidString
}

Create or overwrite document.

try await collection.setDocument(document: movie)
try await collection.setDocument(id: movie.id, document: movie)

Update existing document.

try await collection.updateDocument(document: movie)
try await collection.updateDocument(id: movie.id, document: movie)
try await collection.updateDocument(id: movie.id, dict: try movie.asJsonDictionary())

Get documents.

try await collection.getDocument(id: movie.id)
try await collection.getDocuments(ids: [movie.id, movie.id])
try await collection.getAllDocuments()

Stream documents (add listener via AsyncThrowingStream).

try await collection.streamDocument(id: movie.id) { listener in
     self.listener = listener
}

try await collection.streamAllDocuments { listener in
     self.listener = listener
}

Delete documents.

try await collection.deleteDocument(id: movie.id)
try await collection.deleteDocuments(ids: [movie.id, movie.id])
try await collection.deleteAllDocuments()

About

Convenience functions for using Firebase Firestore with Swift Concurrency (async/await).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages