Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet252/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   248   249   250   251   252   253   254   255   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

database 
scaling
 is handled for you. This is a considerable improvement for large scale 
projects.
Like the Realtime Database, Firestore is free, up to a certain point; you need to pay 
for your database to scale. Firestore charges based on the read and write operations 
that you’re performing on the database.
Because of the improvements that the Firestore offers compared to the Realtime 
Database, Firebase recommends using the Firestore for all new projects.
Cloud Firestore data structure
In this chapter, you learned that the Firestore is a 
NoSQL database
, meaning there 
is no SQL. But if there’s no SQL, you can’t build queries that will take one piece of 
data from one part of the database, and another piece of data from another part of 
the database, and merge them. In the Firestore, to get data from two different parts 
of the database, you must make two different requests. If you run into that scenario, 
it’s likely that you need to re-structure your data in a way that you’ll always be able 
to get what you need in 
one request
.
Saving Data on Android
Chapter 16: Introduction to Cloud Firestore
raywenderlich.com
246


You also learned that the Firestore database consists of collections and documents. 
Take the 
WhatsUp
 app, for example. While it’s possible to have a 
Posts
 collection 
that contains individual posts as documents, 
WhatsUp
 has the feature where every 
post can contain comments. Maybe you can make it so that every post document 
contains a 
Comments
 subcollection, and that that collection contains comments for 
that post. With that setup, you could easily fetch the post and the comments in a 
single call. However, that’s not how you want to do that.
When you think about it, you don’t need to know about the post comments until the 
user opens the post by tapping on it. It’s only when the post details screen appears 
that you need the comments. In this case, a better approach is to have a 
Comments
 
collection stored as a separate collection rather than as a subcollection. You can then 
put the 
post id
 to the individual comment, so you’ll know to which post the 
comment belongs. Finally, when fetching comments, you can filter them by the post 
id and get all of the comments that belong to a specific post.
There is one drawback to this approach, however, and that is data duplication. Every 
comment has an author so you’ll likely want to know who wrote the comment. In 
WhatsUp
 this is not the case, but in other apps, you could have another collection of 
users, and then the comment would need to contain the user data.
By doing that, not only do you fill the database with duplicate user data objects in 
each of the comments but also if the user chooses to change the data, you’ll need to 
update all of the comments, as well. So, perhaps a better approach is to store the 
author id in the comment; then, when you need to get the user data, you can filter 
out the independent 
Users
 collection using the available id.
One significant advantage of the NoSQL database is that it can distribute data across 
multiple machines easily. In relational databases, when you have an app that’s 
becoming more popular and needs more storage space, you’d need a more powerful 
and bigger machine. This is known as 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   248   249   250   251   252   253   254   255   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish