This service allows interacting with an IndexedDB database.
Methods
-
promise
Add a promise to the promise queue. When the promise resolves or rejects, it will be removed from the promise queue.
Parameters:
-
promise
Promise
Returns:
-
type
-
query
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.
Returns:
-
type
-
items
Add one or multiple items to the database.
Parameters:
-
type
StringThe model type to add
-
items
Object | Object[][]One or multiple objects to add to the database.
Returns:
-
type
Clear a database table.
Parameters:
-
type
StringThe model type to clear.
Returns:
Drop the entire database.
Also available as a task: indexedDb.dropDatabaseTask.perform()
Returns:
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:
-
type
-
id
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:
-
type
StringThe model type to find
-
id
String | String[][]One or multiple ids to fetch
Returns:
-
type
Find all of a given type.
Parameters:
-
type
StringThe model type to find.
Returns:
-
config
Import a complete database dump as created by this.exportDatabase()
Also available as a task: indexedDb.importDatabaseTask.perform()
Parameters:
-
config
ObjectA configuration object as created by this.exportDatabase()
Returns:
-
type
-
query
Query indexedDB. This uses _buildQuery under the hood. This resolved to an array.
Returns:
-
type
-
query
Query indexedDB. This uses _buildQuery under the hood. This resolved to an object.
Returns:
-
type
-
item
This will wait for 10ms and try to build a queue, and save everything at once if possible.
Returns:
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:
_promiseQueue
Promise[] privateAll currently running promises are temporarily saved here. This is used to check if there are running transactions.
_savePromise
Promise privateThis is a promise that is used for bulk saving. All bulkSave() operations use and return the same promise, which is cached here.
_saveQueue
Object privateThis 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 privateIf set to true, it will output which indecies are used for queries. This can be used to debug your indecies.
Default: false
_supportsCompoundIndicies
Boolean privatee.g. MS Edge doesn't support compound indices. For these cases, querying shouldn't try to use them.
_testWaiter
Function privateThis is the test waiter used to ensure all promises are resolved in tests. This is set by the this._registerTestWaiter() method.
databaseName
String publicThe database name to use. Overwrite this if you want to use something different.
Default: 'ember-indexeddb'