Hacker News new | past | comments | ask | show | jobs | submit login

My bad if the answer is obvious but (besides backward compatibility/shims + abstraction), what's the benefit of using PouchDB as opposed to vanilla localStorage functionality?



As someone else answered the main use case of PouchDB over plain browser storage is its ability to sync data.

However just wanted to clarify that PouchDB doesnt natively use localstorage for storage, its primarily IndexedDB or WebSQL in the browser (leveldb in node).

We do actually use localstorage for cross tab messaging, but thats mostly a hack due to the lack of idb event listeners (that are coming in v2)


It can sync data between CouchDB servers (e.g. IBM Cloudant) and the browser.


Honestly I didn't know that this is a feature people want (no criticism intended). So, you have a database object in your browser and that takes care of getting the data to the server himself? Otherwise every website syncs data between its browser instances and its database, right? That's how we get state.


The sync happens in an unmanaged fashion, without the user or the application programmer having to care about the state of the connection.

Your PouchDB application works locally on your device, whether the connection is up and down, and the data is synched with the remote database whenever there is connection.

The alternatives to this PouchDB to CouchDB synching mechanism would have to be either:

- the user checks whether the connection is up, and manually manages the sync, or

- the application programmer saves the user the trouble by adding code that checks whether the connection is up, and automatically manages the sync


Using a synced data model provides a few features for users, data access is efficient and far far faster (disk/memory is faster than network) and it allows offline usage (+ failure tolerance, the server goes down the client still works). It can also enable p2p use cases and a bunch of other things, the above 2 are the main drivers though


localStorage quota is 5MB (per ___domain IIRC), PouchDB uses IndexedDB or WebSQL internally, which gives you a lot more quota to work with, and I believe each DB has it's own quota.

localStorage is not indexed, you have to implement some sort of lookup yourself. If you go that way, a tip is to store values as objects with ids as keys, that way you get a sort of hash map as index thing going which alleviates things a bit. PouchDB is indexed and provides a way to query your documents.


Computed views.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: