Skip to content

SwiftfulThinking/SwiftfulFirestore

Repository files navigation

SwiftfulFirestore 🏎️

Package in Alpha.

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 IdentifiableByString (optional).

struct Movie: Codable, IdentifiableByString {
    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.whereField("x", isEqualTo: "x").getAllDocuments()
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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages