Constructor
new DBEngine()
This manages all operations on an IndexedDB. This wraps all operations
in Promises. All Promises will resolve once the transaction has completed.
Depending on the browser, this may or may not be after the data is flushed
to disk. https://goo.gl/zMOeJc
- Implements:
- Source:
Members
-
(private, static) DB_NAME_ :string
-
Type:
- string
- Source:
-
(private, static) DB_VERSION_ :number
-
@const
Type:
- number
- Source:
-
(private, non-null) currentIdMap_ :Object.<string, number>
-
Type:
- Object.<string, number>
- Source:
-
(private) db_ :IDBDatabase
-
Type:
- IDBDatabase
- Source:
-
(private, non-null) operations_ :Array.<shaka.offline.DBEngine.Operation>
-
Type:
- Array.<shaka.offline.DBEngine.Operation>
- Source:
Methods
-
(static) deleteDatabase() → (non-null) {Promise}
-
Delete the database. There must be no open connections to the database.
- Source:
Returns:
- Type
- Promise
-
(static) isSupported() → {boolean}
-
Determines if the browsers supports IndexedDB.
- Source:
Returns:
- Type
- boolean
-
(private, static) onError_(requestnon-null, promisenon-null, event)
-
Rejects the given Promise with an unknown error.
Parameters:
Name Type Description request
IDBRequest promise
shaka.util.PublicPromise event
Event - Source:
-
(private) createOperation_(storeName, type, createRequest, opt_successopt) → (non-null) {Promise}
-
Creates a new transaction for the given store name and calls the given callback to create a request. It then wraps the given request in an operation and returns the resulting promise. The Promise resolves when the transaction is complete, which will be after opt_success is called.
Parameters:
Name Type Attributes Description storeName
string type
string createRequest
function(!IDBObjectStore): !IDBRequest opt_success
function(*) <optional>
The value of onsuccess for the request. - Source:
Returns:
- Type
- Promise
-
destroy() → (non-null) {Promise}
-
Destroys the object, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
- Implements:
- Source:
Returns:
- Type
- Promise
-
forEach(storeName, callback) → (non-null) {Promise}
-
Calls the given callback for each value in the store. The promise will resolve after all items have been traversed.
Parameters:
Name Type Description storeName
string callback
function(T) - Source:
Returns:
- Type
- Promise
-
get(storeName, key) → (non-null) {Promise.<T>}
-
Gets the item with the given ID in the store.
Parameters:
Name Type Description storeName
string key
number - Source:
Returns:
- Type
- Promise.<T>
-
(private) getNextId_(storeName) → (non-null) {Promise.<number>}
-
Gets the ID to start at.
Parameters:
Name Type Description storeName
string - Source:
Returns:
- Type
- Promise.<number>
-
init(storeMapnon-null) → (non-null) {Promise}
-
Initializes the database and creates and required tables.
Parameters:
Name Type Description storeMap
Object.<string, string> A map of store name to the key path. - Source:
Returns:
- Type
- Promise
-
initialized() → {boolean}
-
Gets whether the DBEngine is initialized.
- Source:
Returns:
- Type
- boolean
-
insert(storeName, valuenon-null) → (non-null) {Promise}
-
Adds or updates the given value in the store.
Parameters:
Name Type Description storeName
string value
Object - Source:
Returns:
- Type
- Promise
-
remove(storeName, key) → (non-null) {Promise}
-
Removes the item with the given key.
Parameters:
Name Type Description storeName
string key
number - Source:
Returns:
- Type
- Promise
-
removeWhere(storeName, callback) → (non-null) {Promise.<number>}
-
Removes all items for which the given predicate returns true.
Parameters:
Name Type Description storeName
string callback
function(T): boolean - Source:
Returns:
- Type
- Promise.<number>
-
reserveId(storeName) → {number}
-
Reserves the next ID and returns it.
Parameters:
Name Type Description storeName
string - Source:
Returns:
- Type
- number
Type Definitions
-
Operation
-
Type:
- {transaction: !IDBTransaction, promise: !shaka.util.PublicPromise}
Properties:
Name Type Description transaction
IDBTransaction The transaction that this operation is using. promise
shaka.util.PublicPromise The promise associated with the operation. - Source: