Class: LocalDB

LocalDB(databaseName, versionopt)

Class for managing a local database using IndexedDB.

Constructor

new LocalDB(databaseName, versionopt)

Creates an instance of LocalDB.

Parameters:
Name Type Attributes Default Description
databaseName string

The name of the database.

version number <optional>
1

The database version.

Source:

Methods

(async) aggregate(table, operation, field) → {Promise.<number>}

Performs an aggregation operation on a table.

Parameters:
Name Type Description
table string

The table name.

operation "SUM" | "AVG" | "COUNT" | "MAX" | "MIN"

The aggregation operation.

field string

The field to calculate.

Source:
Returns:

Resolves to the aggregation result.

Type
Promise.<number>

(async) connect(schemaCallback) → {Promise.<IDBDatabase>}

Opens a connection to the database and initializes the schema if needed.

Parameters:
Name Type Description
schemaCallback function

Callback to define the database schema.

Source:
Returns:

Resolves to the database instance.

Type
Promise.<IDBDatabase>

(async) delete(table, key) → {Promise.<void>}

Deletes data from an object store by key.

Parameters:
Name Type Description
table string

The name of the object store.

key IDBValidKey

The key of the data to delete.

Source:
Returns:

Resolves when the operation is successful.

Type
Promise.<void>

(async) insert(table, data) → {Promise.<void>}

Inserts data into an object store.

Parameters:
Name Type Description
table string

The name of the object store.

data Object

The data to insert.

Source:
Returns:

Resolves when the operation is successful.

Type
Promise.<void>

(async) join(tables, joinCondition, resultSelector) → {Promise.<Array.<Object>>}

Performs a join operation between two tables based on a specified condition.

Parameters:
Name Type Description
tables Array.<string>

Array of table names to join (only 2 tables).

joinCondition function

Join condition between the two tables.

resultSelector function

Function to map the join result.

Source:
Returns:

Resolves to an array of join results.

Type
Promise.<Array.<Object>>

(async) query(table, optionsopt) → {Promise.<Array.<Object>>}

Performs a query on an object store with filtering, sorting, and limiting options.

Parameters:
Name Type Attributes Default Description
table string

The name of the object store.

options Object <optional>
{}

Query options (where, orderBy, limit).

Properties
Name Type Attributes Description
where function <optional>

Data filter function.

orderBy string <optional>

Field for sorting ("ASC" or "DESC").

limit number <optional>

Maximum number of data entries to retrieve.

Source:
Returns:

Resolves to the query results.

Type
Promise.<Array.<Object>>

(async) select(table, callback) → {Promise.<Array.<Object>>}

Retrieves all data from an object store that matches the filter callback.

Parameters:
Name Type Description
table string

The name of the object store.

callback function

Filter function.

Source:
Returns:

Resolves to an array of matching data.

Type
Promise.<Array.<Object>>

(async) update(table, key, newData) → {Promise.<void>}

Updates data in an object store by key.

Parameters:
Name Type Description
table string

The name of the object store.

key IDBValidKey

The key of the data to update.

newData Object

The new data to replace the old data.

Source:
Returns:

Resolves when the operation is successful.

Type
Promise.<void>