Usage with Ember Data

The real power of this utility comes together with the provided ember-data adapter. Just extend from it instead of from the default adapter:

import IndexedDbAdapter from 'ember-indexeddb/adapters/indexed-db';

export default class ApplicationAdapter extends IndexedDbAdapter {}

The next step is to setup your database for your Ember Data models. See IndexedDbConfiguration for more details.

A basic setup, without any special database-level querying, would look like this:

import IndexedDbConfigurationService from 'ember-indexeddb/services/indexed-db-configuration';
import { computed, get } from '@ember/object';

export default class ExtendedIndexedDbConfigurationService extends IndexedDbConfigurationService {
 currentVersion = 1;

 version1 = {
   stores: {
     'model-a': '&id',
     'model-b': '&id'
   }
 };
}

Now, you can simply use the normal ember-data store with functions like store.query('item', { isNew: true }). Note that it will also persist data to IndexedDB when calling e.g. createRecord() or save(). If you want to persist data back to an API, you need to handle this yourself. This works with the default JSONAPISerializer.

Note that query and queryRecord will try to do actual querying on the database layer. This will, of course, only work if the indices have been setup correctly. If you try to query by something for which no query exists, it will fall back to filtering via JS (which works, but is much slower).