Simple client-side persistence with a lightweight, promise-based API and multiple storage providers.
As part of a mobile applications development project for The University of Auckland, I needed to store data locally in a mobile application. The technology I initially used (WebSQL) is widely supported but has been abandoned as a standard, so I wanted to future proof by allowing the application to switch to something else depending on what was available on the device. None of the other frameworks available did exactly what I needed, since many required me to repeat my existing data definitions in their particular format, thus making my application less maintainable.
I blended ideas from a number of existing open source projects to come up with my own solution with the following features:
- Designed to work in a browser, including mobile browsers and application containers such as phonegap
- Simple uniform API regardless of the actual data provider used
- All requests return promises to provide uniformity when dealing with asynchronous requests
- Automatically chooses the first available data provider
- Data providers available are IndexedDB, WebSQL, WebStorage (local storage or session storage), cookies or memory
For more information, code examples, and a live demo, see either the Github repository, or the documentation site: http://sarahhenderson.github.io/enduring-stash/
I have released this component as Open Source in case it is useful for anyone else. We are continuing to use it without the mobile applications development project.