Skip to content

IndexedDb

Browser IndexedDB primitives and key schemas for Effect applications.

This module is the low-level bridge used by the platform-browser IndexedDB integration. It provides an IndexedDb service around the browser indexedDB factory and IDBKeyRange constructor, a layerWindow layer for wiring those primitives from window, and schemas for the key shapes accepted by IndexedDB object stores and indexes.

6 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates an IndexedDb service from an IDBFactory and IDBKeyRange constructor.

Signature

declare function make(impl: Omit<IndexedDb, typeof TypeId>): IndexedDb;

Layers

layerWindow

Added in v4.0.0 Source

Layer that provides IndexedDb from window.indexedDB and window.IDBKeyRange, failing with a config error when they are unavailable.

Signature

declare const layerWindow: Layer.Layer<IndexedDb>;

Schemas

Schema for auto-incremented IndexedDB keys, accepting integers from 1 through 2 ** 53.

When to use

Use when you need to define numeric key-path fields for IndexedDbTable definitions that use IndexedDB auto-increment keys.

Details

The schema accepts integer values from 1 through 2 ** 53, matching the range used for generated IndexedDB auto-increment keys.

See

Signature

declare const AutoIncrement: Int;

IDBValidKey

Added in v4.0.0 Source

Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.

Signature

declare const IDBValidKey: Union<
  readonly [
    Union<readonly [String, Number, Date, declare<BufferSource, unknown>]>,
    $Array<Union<readonly [String, Number, Date, declare<BufferSource, unknown>]>>,
  ]
>;

Services

IndexedDb

Added in v4.0.0 Source

Service tag for browser IndexedDB primitives.

Signature

declare const IndexedDb: Service<IndexedDb, IndexedDb>;

IndexedDb interface

Added in v4.0.0 Source

Service interface that provides the browser indexedDB factory and IDBKeyRange constructor.

Signature

interface IndexedDb {
  readonly "~@effect/platform-browser/IndexedDb": "~@effect/platform-browser/IndexedDb";
  readonly IDBKeyRange: {
    (): IDBKeyRange;
    prototype: IDBKeyRange;
    bound(lower: any, upper: any, lowerOpen?: boolean, upperOpen?: boolean): IDBKeyRange;
    lowerBound(lower: any, open?: boolean): IDBKeyRange;
    only(value: any): IDBKeyRange;
    upperBound(upper: any, open?: boolean): IDBKeyRange;
  };
  readonly indexedDB: IDBFactory;
}