FirebaseStorage-Android icon indicating copy to clipboard operation
FirebaseStorage-Android copied to clipboard

how to use local sqlite database along with firebase database android

Open shruity opened this issue 8 years ago • 18 comments

In my app I have SQLite database. I want to introduce sync between devices of my users. I want to combine my local SQLite db with cloud Firebase db.

I want my sqlite database to be stored on firebase database when the users are logged in otherwise let it store offline. Any changes to the local database should be reflected on firebase database when logged in. Also if user deletes the local database he/she can retrieve it from firebase database. I just want to use firebase for the synchronization between local database and firebase database.

But i have no clue how to do it. Can anyone please help me with this? My app is in android with java as a backend.

shruity avatar Aug 23 '16 08:08 shruity

Firebase Realtime Database is able to store datas in the local by firebaseDatabase.setPersistenceEnabled(true); and there is functions to handle an offline mode as well.

For example if connection is offline while you chat, Firebase Realtime Database will store datas what you chat in local till connection back to online Firebase will sync datas in local to Firebase server automatically.

For me I will store datas in SQLite or Realm if I want to use a search function like "%LIKE%" Hope my content above will help you.

jirawatee avatar Aug 25 '16 07:08 jirawatee

I got a little bit understanding only. Basically I have a fitness app and I save the exercise time, their ratios in sqlite and show them in as a report. I want to sync my sqlite data to firebase on button click and the data to be retrieved from firebase and show in the same form as shown by sqlite. I want to use sqlite as a backend but want to provide the user an option so that he can sync the data with firebase if he wants and only when he is logged in. I am facing difficulty to understand how could it be done. I would be grateful if anyone can help me.

shruity avatar Aug 25 '16 10:08 shruity

shruity did you fix your problem?If yes then please guide me how you did that.

waoowa827 avatar May 11 '17 10:05 waoowa827

You can go through the link below: https://www.androidhive.info/2016/10/android-working-with-firebase-realtime-database/

shruity avatar Sep 11 '17 07:09 shruity

to take into account that firebase only stores 10MB offline

jcarlos79t avatar Oct 26 '17 23:10 jcarlos79t

shruity are you using sqlite for local storage ?

sasanksrivatsav avatar Nov 09 '17 08:11 sasanksrivatsav

yes

On Thu, Nov 9, 2017 at 1:58 PM, sasanksrivatsav [email protected] wrote:

shruity are you using sqlite for local storage ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jirawatee/FirebaseStorage-Android/issues/1#issuecomment-343081866, or mute the thread https://github.com/notifications/unsubscribe-auth/AZMYaS6Y9kysVFEDP7I3L96VYVeUY-ttks5s0refgaJpZM4Jqpvn .

waoowa827 avatar Nov 10 '17 14:11 waoowa827

how you sync firestore data with local sqlite data, can you anyone help me

gopib23 avatar Sep 03 '18 23:09 gopib23

Hi, @gopib23 Firestore database already uses SQLite for offline support, hence using a separate SQLIte is not only an overkill but quite unnecessary.

RowlandOti avatar Nov 04 '18 19:11 RowlandOti

@RowlandOti ,Hi, can you provide a Link from where you got that information?

mynormeza avatar Dec 28 '18 16:12 mynormeza

Which information ?

On 28-Dec-2018 9:20 pm, "mynormeza" [email protected] wrote:

@RowlandOti https://github.com/RowlandOti ,Hi, can you provide a Link from where you got that information?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jirawatee/FirebaseStorage-Android/issues/1#issuecomment-450385425, or mute the thread https://github.com/notifications/unsubscribe-auth/Aeg2g7sBJu09cZYBBTx22kh6HeXgLtiZks5u9kTGgaJpZM4Jqpvn .

HamzaMinhaj2019 avatar Dec 28 '18 18:12 HamzaMinhaj2019

Information which proves that Firestore uses SQLite for its offline support.

Hi, @gopib23 Firestore database already uses SQLite for offline support, hence using a separate SQLIte is not only an overkill but quite unnecessary.

mynormeza avatar Dec 28 '18 18:12 mynormeza

Hi, @mynormeza , you can even check the following error: - https://stackoverflow.com/questions/47746100/how-reliable-is-firestore-as-an-offline-persistence-mechanism

The only reason, I would see you having a different cache layer with your own SQLite implementation is when you want to cushion yourself against vendor lockdown. Firestore won't give you access to the local SQLite, so it is better to have one you can access.

RowlandOti avatar Dec 29 '18 17:12 RowlandOti

Related Question: I'm wondering if there's a way I can use SQLite on my backend (not on phone) to do relational stuff, but have Firebase / Firestore keep each Table as a Collection? This way I can have relational SQL queries and reports in my backend, but my Android App has up-to-date access to the data as plain raw collections (tables)?

cgthayer avatar Jun 03 '19 19:06 cgthayer

Am having the same problem.

DavidInnocent avatar Oct 08 '19 18:10 DavidInnocent

please help me to save Realtime data in a local storage for offline support Thanks in advance ..waiting for your reply

meghana-khr avatar Mar 11 '20 10:03 meghana-khr

Firebase Realtime Database is able to store datas in the local by firebaseDatabase.setPersistenceEnabled(true); and there is functions to handle an offline mode as well.

For example if connection is offline while you chat, Firebase Realtime Database will store datas what you chat in local till connection back to online Firebase will sync datas in local to Firebase server automatically.

For me I will store datas in SQLite or Realm if I want to use a search function like "%LIKE%" Hope my content above will help you.

I was using this solution for quite sometime for my app. But now users do a lot a reads and my firestore free limit is getting exhausted daily. So, i want to have SQLite in my app synced with firestore just for changes and not reading all the data to reduce the reads. Is there a way to do this?

ErR0rpj avatar Sep 12 '21 09:09 ErR0rpj

@ErR0rpj hi have you found the solution?

rybandrei2014 avatar Feb 24 '23 07:02 rybandrei2014