Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 1.57 KB

README.md

File metadata and controls

61 lines (49 loc) · 1.57 KB

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()