Constructor Summary
Public Constructor | ||
public |
constructor(cid: String, options: Object) Constructor. |
Member Summary
Public Members | ||
public |
cid: * |
|
public |
dbName: * |
Private Members | ||
private |
_db: * |
|
private |
_options: * |
Method Summary
Public Methods | ||
public |
async clear(): Promise Deletes every records in the current collection. |
|
public |
close(): Promise Closes current connection to the database. |
|
public |
async execute(callback: Function, options: Object): Promise Executes the set of synchronous CRUD operations described in the provided callback within an IndexedDB transaction, for current db store. |
|
public |
async get(id: String): Promise Retrieve a record by its primary key from the IndexedDB database. |
|
public |
async getLastModified(): Promise Retrieve saved lastModified value. |
|
public |
async getMetadata(): * |
|
public abstract |
async importBulk(records: Array): Promise Load records in bulk that were exported from a server. |
|
public |
async list(params: Object): Promise Lists all records from the IndexedDB database. |
|
public abstract |
async loadDump(records: Array): Promise this method was deprecated. Use {@link importBulk} instead.
Load a dump of records exported from a server. |
|
public |
async open(): Promise Ensures a connection to the IndexedDB database has been opened. |
|
public |
async prepare(name: String, callback: Function, options: Object): Object Returns a transaction and an object store for a store name. |
|
public |
async saveLastModified(lastModified: Number): Promise Store the lastModified value into metadata store. |
|
public |
async saveMetadata(metadata: *): * |
Private Methods | ||
private |
_handleError(method: *, err: *) |
Inherited Summary
From class BaseAdapter | ||
public abstract |
clear(): Promise Deletes every records present in the database. |
|
public abstract |
execute(callback: Function, options: Object): Promise Executes a batch of operations within a single transaction. |
|
public abstract |
get(id: String): Promise Retrieve a record by its primary key from the database. |
|
public abstract |
getLastModified(): Promise Retrieve saved lastModified value. |
|
public |
|
|
public abstract |
importBulk(records: Array): Promise Load records in bulk that were exported from a server. |
|
public abstract |
list(params: Object): Promise Lists all records from the database. |
|
public abstract |
loadDump(records: Array): Promise this method was deprecated. Use {@link importBulk} instead.
Load a dump of records exported from a server. |
|
public abstract |
saveLastModified(lastModified: Number): Promise Store the lastModified value. |
|
public |
saveMetadata(metadata: *) |
Public Constructors
public constructor(cid: String, options: Object) source
Constructor.
Params:
Name | Type | Attribute | Description |
cid | String | The key base for this collection (eg. |
|
options | Object | ||
options.dbName | String | The IndexedDB name (default: |
|
options.migrateOldData | String | Whether old database data should be migrated (default: |
Public Members
public cid: * source
public dbName: * source
Private Members
private _db: * source
private _options: * source
Public Methods
public async clear(): Promise source
Deletes every records in the current collection.
Override:
BaseAdapter#clearReturn:
Promise |
Test:
public async execute(callback: Function, options: Object): Promise source
Executes the set of synchronous CRUD operations described in the provided callback within an IndexedDB transaction, for current db store.
The callback will be provided an object exposing the following synchronous CRUD operation methods: get, create, update, delete.
Important note: because limitations in IndexedDB implementations, no asynchronous code should be performed within the provided callback; the promise will therefore be rejected if the callback returns a Promise.
Options:
- {Array} preload: The list of record IDs to fetch and make available to the transaction object get() method (default: [])
Override:
BaseAdapter#executeParams:
Name | Type | Attribute | Description |
callback | Function | The operation description callback. |
|
options | Object | The options object. |
Return:
Promise |
Example:
const db = new IDB("example");
const result = await db.execute(transaction => {
transaction.create({id: 1, title: "foo"});
transaction.update({id: 2, title: "bar"});
transaction.delete(3);
return "foo";
});
Test:
public async get(id: String): Promise source
Retrieve a record by its primary key from the IndexedDB database.
Override:
BaseAdapter#getParams:
Name | Type | Attribute | Description |
id | String | The record id. |
Return:
Promise |
Test:
public async getLastModified(): Promise source
Retrieve saved lastModified value.
Override:
BaseAdapter#getLastModifiedReturn:
Promise |
public abstract async importBulk(records: Array): Promise source
Load records in bulk that were exported from a server.
Override:
BaseAdapter#importBulkParams:
Name | Type | Attribute | Description |
records | Array | The records to load. |
Return:
Promise |
public async list(params: Object): Promise source
Lists all records from the IndexedDB database.
Override:
BaseAdapter#listParams:
Name | Type | Attribute | Description |
params | Object | The filters and order to apply to the results. |
Return:
Promise |
Test:
public abstract async loadDump(records: Array): Promise source
Load a dump of records exported from a server.
Override:
BaseAdapter#loadDumpParams:
Name | Type | Attribute | Description |
records | Array | The records to load. |
Return:
Promise |
public async open(): Promise source
Ensures a connection to the IndexedDB database has been opened.
Return:
Promise |
public async prepare(name: String, callback: Function, options: Object): Object source
Returns a transaction and an object store for a store name.
To determine if a transaction has completed successfully, we should rather listen to the transaction’s complete event rather than the IDBObjectStore request’s success event, because the transaction may still fail after the success event fires.
Params:
Name | Type | Attribute | Description |
name | String | Store name |
|
callback | Function | to execute |
|
options | Object | Options |
|
options.mode | String | Transaction mode ("readwrite" or undefined) |
Return:
Object |
public async saveLastModified(lastModified: Number): Promise source
Store the lastModified value into metadata store.
Override:
BaseAdapter#saveLastModifiedParams:
Name | Type | Attribute | Description |
lastModified | Number |
Return:
Promise |
public async saveMetadata(metadata: *): * source
Override:
BaseAdapter#saveMetadataParams:
Name | Type | Attribute | Description |
metadata | * |
Return:
* |
Private Methods
private _handleError(method: *, err: *) source
Params:
Name | Type | Attribute | Description |
method | * | ||
err | * |