Firebase Firestore
Firestore is a real-time database. Which makes life easier. Firestore is completely managed, serviced and scaled automatically by google firebase.
Some Interesting Features are:
- Real time, NoSQL cloud database (i.e. we don't use tables and columns and rows)
- We split our data up into collections and inside each of those collections we store documents which we can take as records
- Each records has a unique identifier.
- Each records/documents will look something like a JavaScript object with different (Key: Value) pair
- Each fields can have Strings, Arrays, Number, Time, etc...
- We could easy get the whole collections or each documents in collections.
- We can make all database queries using Firebase SDK from frontend to communicate with our database and so we don't worry about backend code.
Implementation:
//firebase
implementation(platform("com.google.firebase:firebase-bom:24.6.0"))
implementation("com.google.firebase:firebase-firestore-ktx")
val listener = Firebase.firestore
.collection(COLLECTION)
.addSnapshotListener { value, error ->
if (error!= null){
close(error)
} else {
if (value != null) {
val list = value.toObjects<Astronaut>()
if (list.isNotEmpty()) {
offer(ApiStatus.success(list))
} else {
offer(ApiStatus.error("Empty List", null))
}
} else {
offer(ApiStatus.error("Error", null))
close(CancellationException())
}
}
}
awaitClose { listener.remove() }
Comments
Post a Comment