npm

Need private packages and team management tools?Check out npm Orgs. »

loki-titanium-adapter

1.1.0 • Public • Published

loki-titanium-adapter

Build Status npm

Titanium SDK adapter for the Loki embedded database.

You can use this library to persist Loki databases inside Titanium applications using the Titanium API. Everything else operates as it would in any other runtime, so visit the Loki documentation for further information.

Usage

This module is on npm, so feel free to grab from there (as well as Loki):

$ npm i lokijs loki-titanium-adapter

You can then configure it inside your application pretty easily, as the API is still synchronous for the time being:

// Load our modules
const Loki = require('lokijs');
const TitaniumAdapter = require('loki-titanium-adapter');
 
// Construct our database instance
const db = new Loki('my-database', {
    adapter: new TitaniumAdapter(),
    autoload: true,
    autosave: true,
    autosaveInterval: 5000,
    autoloadCallback: function () {
        // called when your database is loaded
    },
});

This will save your database changes to disk every 5 seconds (configured via the autosaveInterval parameter). In addition to this, I recommend adding a hook for the pause event to flush when the application is closed:

// Add a pause listener to ensure flush on background
Ti.App.addEventListener('pause', function (_e) {
    db.saveDatabase(function (e) {
        // documents should have been flushed
    });
});

There is also a more complete example app available - just keep in mind that you need to run npm install before you try to run it. For any further use, check out Loki wiki as the API is exactly the same.

install

npm i loki-titanium-adapter

Downloadsweekly downloads

6

version

1.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability