ngx-indexed-db is an Angular service that provides a reactive, observable-based wrapper around the browser's IndexedDB API. It simplifies database interactions for Angular applications, supporting both client-side rendering (CSR) and server-side rendering (SSR) since version 19.2.0. The current stable version is 22.0.0. While the exact release cadence isn't explicitly stated, the version numbers often align with Angular's major releases, suggesting active development. Key differentiators include its observable-driven API, full SSR compatibility, and the ability to provide custom IndexedDB implementations via an injection token for enhanced testing or non-browser environments. It also features a robust migration system for evolving database schemas.
npm install ngx-indexed-dbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates configuring ngx-indexed-db for both NgModule and standalone Angular applications, including defining the database schema and implementing version migrations.
Consult the `ngx-indexed-db` changelog and your Angular version's documentation for compatible package versions. Update `ngx-indexed-db` accordingly.
Upgrade to `ngx-indexed-db@19.2.0` or higher for robust SSR support. If using an older version, ensure IndexedDB operations are guarded by `isPlatformBrowser` or provide a custom `SERVER_INDEXED_DB` token.
Always increment your `DBConfig.version` when modifying the schema. Implement corresponding migration functions in the `migrationFactory` to handle schema updates for existing databases.
Ensure all read/write operations are performed within an active transaction. `ngx-indexed-db`'s observable API generally handles this, but be mindful when directly interacting with the underlying IDB objects if custom logic is involved.
Upgrade to `ngx-indexed-db@19.2.0` or newer. Ensure your SSR setup correctly uses `platform-server` and `ngx-indexed-db` is configured, potentially providing a custom `SERVER_INDEXED_DB` token if needed.
Always increment the `DBConfig.version` when making schema changes. Ensure that a corresponding migration function exists in `migrationFactory` for each version increment that needs to apply schema changes or data transformations.
Ensure all database operations are completed within the lifetime of a single IndexedDB transaction. `ngx-indexed-db`'s service methods manage transactions, so avoid holding references to `objectStore` or `index` objects from a finished transaction.
Verify that `@angular/core` and `ngx-indexed-db` versions are compatible. Ensure `NgxIndexedDBModule.forRoot(dbConfig)` is placed correctly in the `imports` array of an NgModule, or use `provideIndexedDb(dbConfig)` in your providers if using standalone components/bootstrap.