Home Reference Source Test
import IDB from 'kinto/lib/adapters/IDB.js'
public class | source

IDB

Extends:

BaseAdapter → IDB

IndexedDB adapter.

This adapter doesn't support any options.

Test:

Constructor Summary

Public Constructor
public

constructor(cid: String, options: Object)

Constructor.

Member Summary

Public Members
public

cid: *

public

dbName: *

Private Members
private

_db: *

private

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:

NameTypeAttributeDescription
cid String

The key base for this collection (eg. bid/cid)

options Object
options.dbName String

The IndexedDB name (default: "KintoDB")

options.migrateOldData String

Whether old database data should be migrated (default: false)

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#clear

Return:

Promise

Test:

public close(): Promise source

Closes current connection to the database.

Return:

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#execute

Params:

NameTypeAttributeDescription
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#get

Params:

NameTypeAttributeDescription
id String

The record id.

Return:

Promise

Test:

public async getLastModified(): Promise source

Retrieve saved lastModified value.

Override:

BaseAdapter#getLastModified

Return:

Promise

Test:

public async getMetadata(): * source

Override:

BaseAdapter#getMetadata

Return:

*

public abstract async importBulk(records: Array): Promise source

Load records in bulk that were exported from a server.

Override:

BaseAdapter#importBulk

Params:

NameTypeAttributeDescription
records Array

The records to load.

Return:

Promise

Test:

public async list(params: Object): Promise source

Lists all records from the IndexedDB database.

Override:

BaseAdapter#list

Params:

NameTypeAttributeDescription
params Object

The filters and order to apply to the results.

Return:

Promise

Test:

public abstract async loadDump(records: Array): Promise source

this method was deprecated. Use {@link importBulk} instead.

Load a dump of records exported from a server.

Override:

BaseAdapter#loadDump

Params:

NameTypeAttributeDescription
records Array

The records to load.

Return:

Promise

Test:

public async open(): Promise source

Ensures a connection to the IndexedDB database has been opened.

Return:

Promise

Test:

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:

NameTypeAttributeDescription
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#saveLastModified

Params:

NameTypeAttributeDescription
lastModified Number

Return:

Promise

Test:

public async saveMetadata(metadata: *): * source

Override:

BaseAdapter#saveMetadata

Params:

NameTypeAttributeDescription
metadata *

Return:

*

Test:

Private Methods

private _handleError(method: *, err: *) source

Params:

NameTypeAttributeDescription
method *
err *