IndexedDbTable
Typed object-store descriptors for the browser IndexedDB integration.
An IndexedDbTable is the schema-backed description of one IndexedDB object store. It carries the store name, row schema, key path, index key paths, auto-increment mode, and transaction durability used by database versions, migrations, and typed queries. The make constructor also derives the read, array, and auto-increment write schemas used by the query builder.
See
makefor constructing table descriptors.
Constructors
Signature
declare function make<
Name extends string,
TableSchema extends AnySchemaStruct,
Indexes extends Record<string, KeyPath<TableSchema>>,
KeyPath extends
| string
| number
| symbol
| readonly [
IndexedDbValidNumberKeys<NoInfer<TableSchema>>,
IndexedDbValidNumberKeys<NoInfer<TableSchema>>,
]
| readonly [IndexedDbValidKeys<NoInfer<TableSchema>>, IndexedDbValidKeys<NoInfer<TableSchema>>]
| undefined = undefined,
AutoIncrement extends boolean = false,
>(options: {
readonly autoIncrement?: IsValidAutoIncrementKeyPath<TableSchema, KeyPath> extends true
? AutoIncrement | undefined
: never;
readonly durability?: IDBTransactionDurability;
readonly indexes?: Indexes;
readonly keyPath?: KeyPath;
readonly name: Name;
readonly schema: [KeyPath] extends [undefined]
? "key" extends keyof TableSchema["fields"]
? "Cannot have a 'key' field when keyPath is undefined"
: TableSchema
: TableSchema;
}): IndexedDbTable<
Name,
TableSchema,
Indexes,
Extract<KeyPath, Readonly<IDBValidKey | undefined>>,
AutoIncrement
>;Models
Type-erased shape of an IndexedDbTable used when table type parameters are not needed.
Signature
interface Any {
readonly "~@effect/platform-browser/IndexedDbTable": "~@effect/platform-browser/IndexedDbTable";
readonly arraySchema: Top;
readonly autoIncrement: boolean;
readonly autoincrementSchema: Top;
readonly indexes: any;
readonly keyPath: any;
readonly readSchema: Top;
readonly tableName: string;
readonly tableSchema: Top;
}AnySchemaStruct type
Schema constraint for table schemas that expose struct fields.
Signature
type AnySchemaStruct = Schema.Top & {
readonly fields: Schema.Struct.Fields;
};AnyWithProps type
Type-erased IndexedDbTable retaining the table interface properties with broad type parameters.
Signature
type AnyWithProps = IndexedDbTable<string, AnySchemaStruct, any, any, boolean>;IndexedDbTable interface
Typed IndexedDB table definition containing its name, schema, key path, indexes, auto-increment setting, and transaction durability.
Signature
interface IndexedDbTable<
out Name extends string,
out TableSchema extends AnySchemaStruct,
out Indexes extends Record<string, IndexedDbQueryBuilder.KeyPath<TableSchema>>,
out KeyPath extends Readonly<IDBValidKey | undefined>,
out AutoIncrement extends boolean,
> extends Pipeable {
constructor(_: never);
readonly "~@effect/platform-browser/IndexedDbTable": "~@effect/platform-browser/IndexedDbTable";
readonly arraySchema: Top;
readonly autoIncrement: AutoIncrement;
readonly autoincrementSchema: Top;
readonly durability: IDBTransactionDurability;
readonly indexes: Indexes;
readonly keyPath: KeyPath;
readonly readSchema: Top;
readonly tableName: Name;
readonly tableSchema: TableSchema;
}Utility Types
AutoIncrement type
Extracts the auto-increment flag type from an IndexedDbTable.
Signature
type AutoIncrement<Table extends Any> = Table["autoIncrement"];Extracts the decoding or encoding service requirements needed by an IndexedDbTable schema.
Signature
type Context<Table extends Any> =
| Table["tableSchema"]["DecodingServices"]
| Table["tableSchema"]["EncodingServices"];Extracts the encoded row type from an IndexedDbTable schema.
Signature
type Encoded<Table extends Any> = Table["tableSchema"]["Encoded"];Extracts the index definition map from an IndexedDbTable.
Signature
type Indexes<Table extends Any> = Table["indexes"];Extracts the key-path type from an IndexedDbTable.
Signature
type KeyPath<Table extends Any> = Table["keyPath"];Extracts the table name type from an IndexedDbTable.
Signature
type TableName<Table extends Any> = Table["tableName"];TableSchema type
Extracts the schema type from an IndexedDbTable.
Signature
type TableSchema<Table extends Any> = Table["tableSchema"];Selects the table with the given name from a union of IndexedDbTable types.
Signature
type WithName<Table extends Any, TableName extends string> = Extract<
Table,
{
readonly tableName: TableName;
}
>;
Creates a typed IndexedDB table definition from its name, schema, optional key path, indexes, auto-increment flag, and durability.
When to use
Use to define a typed object-store descriptor for inclusion in an
IndexedDbVersionand for migration or query APIs.Details
autoIncrementdefaults tofalseanddurabilitydefaults to"relaxed". Tables without a key path get a read schema that includes an out-of-linekey, while auto-increment tables use a write schema where the generated key may be omitted.Gotchas
Tables without a key path cannot define a
keyfield in their row schema. Key paths and index paths must point to encoded fields whose values are valid IndexedDB keys, and declared indexes still need to be created during database migrations.See
IndexedDbVersion.makefor grouping table definitions into a schema version