https://github.com/swiftfulthinking/swiftfulfirestore
Convenience functions for using Firebase Firestore with Swift Concurrency (async/await).
https://github.com/swiftfulthinking/swiftfulfirestore
firebase-firestore firestore-collection firestore-database swift
Last synced: about 1 year ago
JSON representation
Convenience functions for using Firebase Firestore with Swift Concurrency (async/await).
- Host: GitHub
- URL: https://github.com/swiftfulthinking/swiftfulfirestore
- Owner: SwiftfulThinking
- Created: 2023-12-10T19:20:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-31T00:58:56.000Z (over 2 years ago)
- Last Synced: 2024-01-01T00:38:41.989Z (over 2 years ago)
- Topics: firebase-firestore, firestore-collection, firestore-database, swift
- Language: Swift
- Homepage: https://www.swiftful-thinking.com/
- Size: 32.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SwiftfulFirestore 🏎️
Convenience functions for using Firebase Firestore with Swift Concurrency.
Most functions are an extension of CollectionReference.
## Usage
Import the package to your project.
* File -> Swift Packages -> Add Package Dependency
* Add URL for this repository: https://github.com/SwiftfulThinking/SwiftfulFirestore.git
#### Import the package to your file.
```swift
import SwiftfulFirestore
```
#### Conform to StringIdentifiable (optional).
```swift
struct Movie: Codable, StringIdentifiable {
let id = UUID().uuidString
}
```
#### Create or overwrite document.
```swift
try await collection.setDocument(document: movie)
try await collection.setDocument(id: movie.id, document: movie)
```
#### Update existing document.
```swift
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.
```swift
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).
```swift
try await collection.streamDocument(id: movie.id) { listener in
self.listener = listener
}
try await collection.streamAllDocuments { listener in
self.listener = listener
}
```
#### Delete documents.
```swift
try await collection.deleteDocument(id: movie.id)
try await collection.deleteDocuments(ids: [movie.id, movie.id])
try await collection.deleteAllDocuments()
```