This service allows interacting with an IndexedDB database.

Show:
_addToPromiseQueue
(
  • promise
)
Promise
private

Add a promise to the promise queue. When the promise resolves or rejects, it will be removed from the promise queue.

Parameters:

Returns:

_buildQuery
(
  • type
  • query
)
Dexie.Collection
private

Build a query for Dexie.

This will try to find a matching index, and use it if possible. It can also handle multi-indecies, if they have been specified and are supported. If no matching index is found, it will fetch everything and try to filter it via JS. Note that this is much slower than querying by actual indecies, so you should definitely use that if possible! If you are using multiple query arguments, and only one of them is found as index, it will query the database by this index and then do the other queries via JS filter.

Note that this will also auto-convert boolean query arguments to 1/0.

Parameters:

  • type String

    The model type to query

  • query Object

    The actual query

Returns:

Dexie.Collection
_bulkSave () private

Get the queue and save everything in it in bulk.

add
(
  • type
  • items
)
Promise
public

Add one or multiple items to the database.

Parameters:

Returns:

clear
(
  • type
)
Promise
public

Clear a database table.

Parameters:

  • type String

    The model type to clear.

Returns:

delete
(
  • type
  • id
)
Promise
public

Delete one item.

Parameters:

  • type String

    The model type to delete

  • id String

    The id of the entry to delete

Returns:

dropDatabase () Promise public

Drop the entire database.

Also available as a task: indexedDb.dropDatabaseTask.perform()

Returns:

exportDatabase () Promise public

Export a complete dump of the current database. The output of this can be used to recreate the exact database state via this.importDatabase(config);

Also available as a task: indexedDb.exportDatabaseTask.perform()

Returns:

find
(
  • type
  • id
)
Promise
public

Find one or multiple items by id. If id is an array, this will try to fetch all of these objects and resolve with an array. Otherwise, it will resolve with an object.

Parameters:

Returns:

findAll
(
  • type
)
Promise
public

Find all of a given type.

Parameters:

  • type String

    The model type to find.

Returns:

importDatabase
(
  • config
)
Promise
public

Import a complete database dump as created by this.exportDatabase()

Also available as a task: indexedDb.importDatabaseTask.perform()

Parameters:

  • config Object

    A configuration object as created by this.exportDatabase()

Returns:

query
(
  • type
  • query
)
Promise[][]
public

Query indexedDB. This uses _buildQuery under the hood. This resolved to an array.

Parameters:

  • type String

    The model type to query

  • query Object

    The query data

Returns:

queryRecord
(
  • type
  • query
)
Promise
public

Query indexedDB. This uses _buildQuery under the hood. This resolved to an object.

Parameters:

  • type String

    The model type to query

  • query Object

    The query data

Returns:

save
(
  • type
  • id
  • item
)
Promise
public

Save/update an item.

Parameters:

  • type String

    The model type of the object

  • id String

    The id of the object

  • item Object

    The serialized object to save.

Returns:

saveBulk
(
  • type
  • item
)
Promise
public

This will wait for 10ms and try to build a queue, and save everything at once if possible.

Parameters:

  • type String

    The model type to save

  • item Object

    The data to save

Returns:

setup () Promise public

Call this and wait until it resolves before doing anything with IndexedDB! This should be done in beforeModel() on the application route. It will reject if IndexedDB is not available.

Also available as a task: indexedDb.setupTask.perform()

Returns:

waitForQueue () Promise public

Wait for all queued objects ot be resolved. This will resolve when there are no open processes anymore.

Also available as a task: indexedDb.waitForQueueTask.perform()

Returns:

_promiseQueue

Promise[] private

All currently running promises are temporarily saved here. This is used to check if there are running transactions.

_savePromise

Promise private

This is a promise that is used for bulk saving. All bulkSave() operations use and return the same promise, which is cached here.

_saveQueue

Object private

This is an object with an array per model type. It holds all the objects per model type that should be bulk saved. After actually saving, this will be cleared.

_shouldLogQuery

Boolean private

If set to true, it will output which indecies are used for queries. This can be used to debug your indecies.


Default: false

_supportsCompoundIndicies

Boolean private

e.g. MS Edge doesn't support compound indices. For these cases, querying shouldn't try to use them.

_testWaiter

Function private

This is the test waiter used to ensure all promises are resolved in tests. This is set by the this._registerTestWaiter() method.

databaseName

String public

The database name to use. Overwrite this if you want to use something different.


Default: 'ember-indexeddb'

db

Dexie public

The actual Dexie database.