Code Monkey home page Code Monkey logo

localforage-cordovasqlitedriver's Introduction

localForage-cordovaSQLiteDriver

npm
SQLite driver for Cordova apps using localForage.

Requirements

Install Dependencies

  • install Cordova-sqlite-storage plugin cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
  • install localForage-cordovaSQLiteDriver
    • via npm with: npm i --save localforage localforage-cordovasqlitedriver (ionic 2 users might prefer ths one)
    • via bower with: bower install --save localforage localForage-cordovaSQLiteDriver

CHANGELOG

v1.3

Reduce driver size (almost by 50%) by "inheriting" the method implementations of the localforage.WEBSQL driver.

v1.2 BREAKING CHANGE

Add support for newer versions of Cordova SQLite storage plugin (v0.8.x & v1.2.x).

UPGRADE WARNING: The default storage location for SQLite has changed in newer versions of Cordova SQLite storage plugin. The new "default" location value is NOT the same as the old "default" location and will break an upgrade for an app that was using the old default value (0) on iOS. If you are upgrading to a newer version of localForage-cordovaSQLiteDriver you need to verify where your previous storage location was and update the location property of the localForage database. Otherwise the default is 'default'. This is to avoid breaking the iCloud Design Guide. See here for further details.

v1.1

Try using the getSerializer() (available in localforage v1.3) as the prefered way to retrieve the serializer.

Setup Your Project

  • Include localforage and localForage-cordovaSQLiteDriver in your main html page, after the cordova include.
  • Call defineDriver and setDriver to make localForage use the cordovaSQLiteDriver.
<script src="cordova.js"></script>

<script src="lib/localforage/dist/localforage.js"></script>
<script src="lib/localForage-cordovaSQLiteDriver/src/localforage-cordovasqlitedriver.js"></script>
<script>
localforage.defineDriver(window.cordovaSQLiteDriver).then(function() {
    return localforage.setDriver([
    	// Try setting cordovaSQLiteDriver if available,
      window.cordovaSQLiteDriver._driver,
      // otherwise use one of the default localforage drivers as a fallback.
      // This should allow you to transparently do your tests in a browser
      localforage.INDEXEDDB,
      localforage.WEBSQL,
      localforage.LOCALSTORAGE
    ]);
}).then(function() {
  // this should alert "cordovaSQLiteDriver" when in an emulator or a device
  alert(localforage.driver());
  // set a value;
  return localforage.setItem('testPromiseKey', 'testPromiseValue');
}).then(function() {
  return localforage.getItem('testPromiseKey');
}).then(function(value) {
  alert(value);
}).catch(function(err) {
  alert(err);
});
</script>

Examples

localforage-cordovasqlitedriver's People

Contributors

thgreasi avatar zbarbuto avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.