Firebase Offline Support?


#1

i Have 2 Questions about the offline support , Because If have an directory app and i `m not want my users to load the data every time open the app because when if they offline can show the data that they viewed before disconncet , are the firebase Offline Capabilities support it ?
if not i need example or idea to load the data when the first time install the app , and not that i use firebase realtime database?

thank you …


#2

See Enabling Offline Capabilities in the Firebase docs.


#3

Firebase offline capabilities are to allow you to do crud like operation even when you are offline for short periods of time.
For what you want you will most likely need to use local dB on device and keep it is sync with firebase…In this case you serve content from local db. Complicated thinng here would be to write your logic to keep your local db in sync with firebase.


#4

i read the docs but i didn`t understand how to make what i write in the post above ?
can you give me simple example with ionic 2 and typescript ?


#5

i Need Example to how to do this ? can you help me ?


#6

I can give you some suggestion.
Map the data from firebase to sqlite. Since sqlite is not schema less db you will need to store the data as JSON.stringify from firebase data. You can not search the stringified json however so you will need to create columns from the firebase data that you want to search locally in addition to the the JSON data you store as string in another column in same table to sync back to server.

Every change you make to the data will change the columns locally in the table and also in the json.parse of the data you have saved as string in the table.

You can make a new table locally that will keep these changed data objects along with the reference to the firebase DB,

You can create an observer that keep track of any addition to this table and anytime there is data in this table you use the firebase ref saved along with data and use it to update server if user online. On success callback remove this row from the table locally so that you don’t sync this up again in future.

You can also create observer on firebase tables to sync down to local table same way if new child is added on server from another client device.

This is one logic I have used but I am sure there can be some other flow too,


#7

I just made a library to provide Firebase offline support for Angular 2 and Ionic. Here’s an Ionic tutorial. Feel free to contribute too. Thanks!


#8

Great work Adrian. I can see all the love you put on this.

My problem is that i’m heavily related to a php/mysql server, do you think there is a way to get rid of firebase?