Can I use CouchDB mobile as a replacement for localStorage?
Asked Answered
S

3

14

I have an existing web app that runs offline (using HTML5 cache manifest).

I am storing data in localStorage. I am going to hit the 5Mb limit for localStorage. Can I use CouchDB as a local db, effectively replacing localStorage with the CouchDB implementation?

I don't want to install CouchDB on any servers, I just want to leverage the client-side storage capability to replace my localStorage implementation.

Is it as simple as downloading the relevant couchdb.js files and altering my client-side persistence code?

Thanks

Spiritism answered 1/9, 2011 at 17:0 Comment(0)
A
9

As usual "it depends"

If your application is being served from a website then no, there are projects like pouchdb which aim to provide a client side version of CouchDB, however they arent going to help you avoid the limitations of a browser

If you are shipping your application as a standalone application then yes, it should be a fairly simple matter of following the installation instructions to add CouchDB to your application:

and having your client code make couch requests instead of localStorage ones, remembering that:

  1. localStorage only stores strings and CouchDB stores JSON, and
  2. calls to Couch are asynchronous and localStorage are synchronous, neither of those should be particularly big changes in javascript though.

The other main option to look at would be PhoneGap which will provide you access to the native storage API's from the device while still dealing in html / javascript, its a cross platform library that allows you to access native API's including the Storage API that wont have browser limitations - http://docs.phonegap.com/phonegap_storage_storage.md.html#Storage

PhoneGap will also require you to ship as an application and not a website (its the only way to not be limited by the browser).

Approximal answered 2/9, 2011 at 2:33 Comment(0)
R
6

This should be updated. PouchDB now uses IndexedDB which on most browsers I have tried does not have size limits (or is an option). I am storing several 100MB of map tiles in a browser.

See: https://gis.stackexchange.com/questions/62070/offline-slippy-map-tiles-database-for-leaflet/62073#62073

Rathskeller answered 28/6, 2013 at 13:9 Comment(0)
H
3

A short answer is that installing Couchbase Mobile on your phone requires you to ship as an application, and the Couch APIs it has are more full featured than the localStorage APIs.

If you want to get a sense for what you can do in the scope of CouchDB's web apis (not mobile specific, but handy on mobile), see this architecture document.

Helgahelge answered 2/9, 2011 at 15:26 Comment(1)
Caveat that's easily missed for those new to the technologies. Couchbase is not CouchDB, it's memcache NoSQL server (Membase Server) speaking similar protocol to CouchDB for replication. Mostly the same but it works differently under the hood and some output is not what you'd expect from CouchDB. #5579108Haphazard

© 2022 - 2024 — McMap. All rights reserved.