Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Database<DBSchema>

A wrapper for an IndexedDB connection.

Call Database.open to create a new database connection.

typeparam

The schema for the database, along with the allowed names for databases using that schema.

Type parameters

Hierarchy

  • Database

Index

Properties

Methods

Properties

name

name: string

The name of the IndexedDB database.

Methods

close

  • close(): void
  • Request to close the database connection.

    If there are no open transactions, this will close immediately. If any transactions are open, it will wait for them to complete before closing. This happens asynchronously, out of band.

    Returns void

get

  • get<DBStoreName>(storeName: DBStoreName, key: StoreKey<DBSchema["schema"], DBStoreName>): Promise<StoreValue<DBSchema["schema"], DBStoreName> | undefined>
  • Get a value from a store.

    Resolves to undefined if no value exists for the given key in the given store.

    Type parameters

    Parameters

    • storeName: DBStoreName
    • key: StoreKey<DBSchema["schema"], DBStoreName>

    Returns Promise<StoreValue<DBSchema["schema"], DBStoreName> | undefined>

put

  • put<DBStoreName>(storeName: DBStoreName, key: StoreKey<DBSchema["schema"], DBStoreName>, value: StoreValue<DBSchema["schema"], DBStoreName>): Promise<void>
  • Create or update a value in a store.

    Type parameters

    Parameters

    • storeName: DBStoreName
    • key: StoreKey<DBSchema["schema"], DBStoreName>
    • value: StoreValue<DBSchema["schema"], DBStoreName>

    Returns Promise<void>

transaction

  • transaction<DBStoreNames>(storeNames: DBStoreNames, tx: (stores: StoreMap<DBSchema["schema"], DBStoreNames>) => void | Promise<void>, mode?: TransactionMode): Promise<void>
  • Create a transaction on one or more stores.

    Type parameters

    Parameters

    • storeNames: DBStoreNames

      The stores to open the transaction over.

    • tx: (stores: StoreMap<DBSchema["schema"], DBStoreNames>) => void | Promise<void>

      A callback for the transaction to call. Be aware that this callback, although possibly asynchronous, needs to be updating the transaction every tick. If no changes to the transaction happen in a tick, it will automatically commit itself and the transaction will close.

        • (stores: StoreMap<DBSchema["schema"], DBStoreNames>): void | Promise<void>
        • Parameters

          • stores: StoreMap<DBSchema["schema"], DBStoreNames>

          Returns void | Promise<void>

    • Default value mode: TransactionMode = TransactionMode.ReadOnly

      The mode to open the transaction in.

    Returns Promise<void>

Static open

  • open<DBSchema>(name: DBSchema["dbNames"], version: DBSchema["versions"], openOptions?: OpenOptions<DBSchema["schema"]>): Promise<Database<DBSchema>>
  • Open a new database connection.

    typeparam

    The schema for the database, along with the allowed names for databases using that schema.

    Type parameters

    Parameters

    • name: DBSchema["dbNames"]

      The name of the database.

    • version: DBSchema["versions"]

      The schema version you want to open. This can only ever increase. See OpenOptions.upgrade for how to upgrade the schema when changing version.

    • Default value openOptions: OpenOptions<DBSchema["schema"]> = {}

      The options and callbacks for opening the database. See OpenOptions for details.

    Returns Promise<Database<DBSchema>>

    A promise to an open Database ready to be accessed.

Generated using TypeDoc