Home Reference Source Test
public class | source

JungleDB

Implements:

Static Method Summary

Static Public Methods
public static

async commitCombined(tx1: Transaction | CombinedTransaction, tx2: Transaction, txs: ...Transaction): Promise<boolean>

Is used to commit multiple transactions atomically.

public static

Creates a volatile object store (non-persistent).

Constructor Summary

Public Constructor
public

constructor(name: string, dbVersion: number, options: function(oldVersion: number, newVersion: number, jdb: JungleDB))

Initiates a new database connection.

Member Summary

Public Members
public get

backend: IDBDatabase

public get

connected: boolean

Method Summary

Public Methods
public

async close(): Promise

Closes the database connection.

public

connect(): Promise<IDBDatabase>

Connects to the indexedDB.

public

createObjectStore(tableName: string, options: ObjectStoreConfig): IObjectStore

Creates a new object store (and allows to access it).

public

deleteObjectStore(tableName: string, options: function(oldVersion: number, newVersion: number): boolean}, indexNames)

Deletes an object store.

public

async destroy(): Promise

Fully deletes the database.

public

getObjectStore(tableName: string): ObjectStore

Returns the ObjectStore object for a given table name.

public

toString(): string

Static Public Methods

public static async commitCombined(tx1: Transaction | CombinedTransaction, tx2: Transaction, txs: ...Transaction): Promise<boolean> source

Is used to commit multiple transactions atomically. This guarantees that either all transactions are written or none. The method takes a list of transactions (at least two transactions). If the commit was successful, the method returns true, and false otherwise.

Params:

NameTypeAttributeDescription
tx1 Transaction | CombinedTransaction

The first transaction (a CombinedTransaction object is only used internally).

tx2 Transaction

The second transaction.

txs ...Transaction

A list of further transactions to commit together.

Return:

Promise<boolean>

A promise of the success outcome.

public static createVolatileObjectStore(options: {codec: ?ICodec}): ObjectStore source

Creates a volatile object store (non-persistent).

Params:

NameTypeAttributeDescription
options {codec: ?ICodec}
  • optional

An options object.

Return:

ObjectStore

Public Constructors

public constructor(name: string, dbVersion: number, options: function(oldVersion: number, newVersion: number, jdb: JungleDB)) source

Initiates a new database connection. All changes to the database structure require an increase in the version number. Whenever new object stores need to be created, old ones deleted, or indices created/deleted, the dbVersion number has to be increased. When the version number increases, the given function onUpgradeNeeded is called after modifying the database structure.

Params:

NameTypeAttributeDescription
name string

The name of the database.

dbVersion number

The current version of the database.

options function(oldVersion: number, newVersion: number, jdb: JungleDB)
  • optional

Public Members

public get backend: IDBDatabase source

public get connected: boolean source

Public Methods

public async close(): Promise source

Closes the database connection.

Return:

Promise

The promise resolves after closing the database.

public connect(): Promise<IDBDatabase> source

Connects to the indexedDB.

Return:

Promise<IDBDatabase>

A promise resolving on successful connection. The raw IDBDatabase object should not be used.

public createObjectStore(tableName: string, options: ObjectStoreConfig): IObjectStore source

Creates a new object store (and allows to access it). This method always has to be called before connecting to the database. If it is not called, the object store will not be accessible afterwards. If a call is newly introduced, but the database version did not change, the table does not exist yet.

Params:

NameTypeAttributeDescription
tableName string

The name of the object store.

options ObjectStoreConfig
  • optional

An options object.

Return:

IObjectStore

public deleteObjectStore(tableName: string, options: function(oldVersion: number, newVersion: number): boolean}, indexNames) source

Deletes an object store. This method has to be called before connecting to the database.

Params:

NameTypeAttributeDescription
tableName string
options function(oldVersion: number, newVersion: number): boolean}, indexNames
  • optional

public async destroy(): Promise source

Fully deletes the database.

Return:

Promise

The promise resolves after deleting the database.

public getObjectStore(tableName: string): ObjectStore source

Returns the ObjectStore object for a given table name.

Params:

NameTypeAttributeDescription
tableName string

The table name to access.

Return:

ObjectStore

The ObjectStore object.

public toString(): string source

Return:

string