Database control model for Android Application - android

I want to make a model that plays an intermediate role between the database and my frontend in the android application.
Why do I want to do this?
suppose now I am using directly firebase database but in the future, if I want to change the database then I will have to change all the functionality where the database connection is implemented. So I want to make a generalized model so I will change in model and work will become easy to change the database platform for me and my project team also.
How I can do this and by which model?
Note: I used a NoSQL database(Firebase) now and future changed database will be also NoSQL database(like mongoDB).

Related

What is the performance difference between using DataStore vs ContentProvider

I have been storing login credentials using the new Android DataStore. Has been working well, but now I need to share it between multiple apps using ContentProvider.
The problem is, I don't want to have another layer of maintenance by always having to remember to update the ContentProvider with the credentials while also updating the DataStore.
So the idea is, to use only the ContentProvider. But I'm afraid of the performance impact of changing the flow from:
App <--> DataStore
to:
App <--> ContentProvider <--> Room Database
Does anyone know how bad this change is for performance? Also, for some reasons I'm using Room Database as the storage for the ContentProvider.

Android Preferences DataStore vs Existing Room Implementation

I’m new to Android development and I’m about to implement simple Preferences for my app. It appears SharedPreferences is a dead end and has lots of warts, so I’m looking at DataStore (non-Proto) vs Room. Since I ALREADY heavily use Room and LiveData (yes, I know Flow is the new hotness) in my app for other things, is there any benefit to using DataStore too? I understand Room is recommended for large or complex data as I’ve already reviewed the following, but I’m hoping a more seasoned developer can further hit this home for me:
https://android-developers.googleblog.com/2020/09/prefer-storing-data-with-jetpack.html
https://proandroiddev.com/lets-explore-jetpack-datastore-in-android-621f3564b57
https://medium.com/better-programming/jetpack-datastore-improved-data-storage-system-adec129b6e48
Thank you.
The official blog post you linked has a section specifically about Room vs DataStore:
If you have a need for partial updates, referential integrity, or support for large/complex datasets, you should consider using Room instead of DataStore. DataStore is ideal for small , simple datasets and does not support partial updates or referential integrity.
User preferences almost always fall into the 'small, simple datasets' that can be easily expressed as key/value pairs (or something more complicated if you want to use the Proto DataStore) that do not need the overhead of a table schema, SQL queries, custom parsing, or the 'relational' part of a relational database.
The problem with datastore is you cannot just fetch or update a part of data from a list like you can with SQLite libraries such as Room. This is true for both Proto and Preferences version. So if you have 10 thousand elements and you save them to DataStore and then you want to update 2 of them based on a condition you'll have to fetch the entire list, manipulate it and put it back. Here Room (or any DB solution) will be a way to go
But if you just want to save user preferences or small data it would be an overkill to use a DataBase - here DataBase Proto will actually be the perfect choice

How to modify firebase offline data via android?

The android app I am currently developing will mainly run offline. However while online, the users can connect to the DB to download the data they need. Furthermore they are able to manage the data offline, so they can remove the data they don't want to use. The users cannot modify the online database.
I am using Firebase with its Persistence enabled feature, to save the date for online use. My problem is, that I just cannot manage the data properly.
Since firebase downloads the whole database:
Is there a way to choose, which queries I want to download form firebase?
If not, can I delete those queries I don't want to use, from local content?
It looks like you don't want the sync feature of the firebase database.
However while online, the users can connect to the DB to download the
data they need. Furthermore they are able to manage the data offline,
so they can remove the data they don't want to use. The users cannot
modify the online database.
set write as false for this table in the rules and the modification will not be possible, since you have enabled disk persistence firebase will read the newer updates but wont write the user changes. Also it might discard the existing changes of the user(which the user removed) during the sync and put the newer ones from the cloud, so you might(as I have never tried this) end up doing the sync yourself, please search and read up on this.
Since firebase downloads the whole database: Is there a way to choose,
which queries I want to download form firebase? If not, can I delete
those queries I don't want to use, from local content?
You will have to turn off on the sync on the each of your table like shown below
DatabaseReference dbRef=FirebaseDatabase.getInstance().getReference("table-name");
dbRef.keepSynced(false);
Refer here in the docs. I think this has to be done on each node as there is no way to turn it off on the entire firebase realtime DB except disable disk persistance which you want in your case.
IMHO it looks like you are using firebase as a place to store your data in the cloud, in case the sync feature ends up discarding your local changes to sync the online ones you should consider using SQL-lite DB with Room ORM as it will serve your purpose of just fetching the data and modifying it locally, however the tradeoff here is that you will have to maintain the data in a proper manner to query the newer changes or see if there is any updates/deletes on any of the older records.

Can we keep a common repository for SQLLite in which android apps can do CRUD operations?

I am creating an android application. Users will do select, insert, update operations on database. SQLLite is specific to a device(correct me if I am wrong) i.e., local storage. But, I want to maintain a central repository from which all the users will access the data. Can we achieve this with SQLLite? Or is there any other way to achieve this?
Thanks.

One to one synchronization of SQLite db between app and server

In my app I have a SQLite DB want to backup to server but what I want is one to one synchronization for off-line backup (e.g. standalone SQLite file instead of a centralized MySQL server, mainly performance reason and I don't need real time query)
Ideally I don't want to upload the database everytime when I need to sync, prefer only sync the changes?
Are there any existing solution for this? (I can consider using other file DB as currently I mainly use SQLite as Key-Value database)
Thanks.
As you are willing to consider using a different DB, take a look at TouchDB-Android. This syncs a database on an Android device to a CouchDB server. There is a related project SyncPoint, that automates setting up a database for each user.
We are using TouchDb-iOS for our product at the moment are planning work on an Android version using TouchDB-Android soon.
The development community is active. Check out the user group.

Categories

Resources