Offline Firebase

孤人 提交于 2019-11-30 07:01:42

An alternative to Firebase that solves this problem for JS apps is CouchDb (server) <=> PouchDb (JS client). If you've implemented a nice clean Service layer for your AngularJS app then porting to PouchDb should be fairly straight forward since both are NoSQL/JSON databases.

PouchDb is a Javascript API that implements a fully offline CouchDb client. It can auto detect and use either _local storage_, _IndexDb_ or _WebSQL_ to permanently persist local data while online or offline. The PouchDb API can be used to access either your local or remote databases (just change the URL) and wire up full syncing or filtered syncing between the two. There are many useful PouchDb plugins, code samples and a small wrapper library to support AngularJS's Q promises API.

Using PouchDb, you can safely start up your app while offline and then days later restart your app and sync all your CUD data changes to the server. This can result in update collisions so CouchDb supports record versioning that is designed to detect and track this. Consequently, you'll likely need server side logic to resolve these collisions. This is unavoidable for distributed systems with offline synchronization and a key feature of CouchDb (not quite true ... see comments)

PouchDb is basically a reimplementation of Apache CouchDb including it's efficient synchronization protocol. Both CouchDb and PouchDb are well tested, free and open source. Being open source means that a CouchDb server can also be deployed as an Intranet service - optionally syncing to an external cloud service. There are a number of CouchDb hosting providers.

The Cloudant hosting team recently added their BigCouch clustering features to Apache CouchDb 2.0 project so now you can scale from Micro Db (PouchDb) => Single Server => Multi-Master (Replicated) => Big Couch Clustered / Geo Clustered. Unlike MongoDb, CouchDb safely supports single server deployment.

NOTE: PouchDb can also sync to CouchBase using the same protocol but Couchbase !== CouchDb. It's a commercial product.

Links:

CouchDb Hosters:

DIY

Docker + CouchDb:

Truck load of Plugins

PouchDb has a number of extension points and growing list plugins (37 last count):

Security Model

One issue you'll need to consider when migrating to CouchDb is that it has a more limited access control model. This is partly due to it's replication algorithm. This blog post covers this in detail (better than the real definitive guide).

According to the Firebase docs, it does: https://www.firebase.com/docs/web/guide/offline-capabilities.html

From the site: Firebase provides some simple primitives that allows data to be written when a client disconnects from the Firebase servers. These updates will occur whether the client disconnects cleanly or not, so we can rely on them to clean up data even if a connection is dropped or a client crashes. All Firebase write operations, including setting, updating, and removing, can be performed upon a disconnection.

Am I interpreting the question incorrectly ?

I almost deleted my post but when I clicked on the link OP had given, I saw that the third party package does exactly the same thing as what Firebase itself does, maybe it was done before Firebase improved sync ?

When I deleted the post, I thought the OP might have wanted a selective set of data only, not 'active data' which is what FB stores locally until connection is restored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!