idb-easier
v1.3.1
Published
indexedDB storage: Make using 'idb' even easier!
Maintainers
Readme
idb-easier
Overview
idb-easier is a simple wrapper for idb -- which is itself a wrapper for making indexedDB more usable.
Installation
npm i idb-easier
OR
bun i idb-easierUsage
my-ui-component.ts
import {
IdbConfig,
idbConnectDatabase as useDB,
idbDeleteDatabase,
idbGet,
idbSet
} from 'idb-easier'
// ---------------------------
// Define indexedDB Parameters
// ---------------------------
const IDB_CONFIG = Object.freeze({
dbName: 'myDatabase',
storeName: 'myStore',
// OPTIONAL key
//
// indexConfig is an optional config key.
// It is used if you use an index.
//
// Refer to indexedDB documentation for more details.
indexConfig: {
indexName: 'timestamp',
keyPath: 'id',
autoIncrement: true,
},
})
// The `db` object is returned to optionally give the developer
// direct access to `idb` package's db methods not included/wrapped
// in the this `idb-easier` package.
const db = await useDB(IDB_CONFIG: IdbConfig).catch((err) => {
console.trace(err.message)
})
await idbSet(myData, 'my-key')
const data = await idbGet('my-key')Delete Database
// Pass in dbName and catch error if delete fails.
await idbDeleteDatabase(IDB_CONFIG.dbName).catch((err) => {
console.trace(err.message)
})
// If delete has no errors, db no longer exists. idbConnectDatabase()
// must be called again to use the idbSet() and idbGet() methods.Delete a Record in the Store
await idbDeleteRecord(IDB_CONFIG.storeName, 'my-key')Get All Records Filtered By Key Prefix
Retrieve all records in which the DB keys match the prefix string.
Limitations
prefix only, no suffix matching
matching is case sensitive
// The database's keys have country code prefixes:
//
// 'jp:companyZ'
// 'sg:companyA'
// 'tw:companyL'
// 'sg:companyB'
// 'sg:companyC'
const singaporeanItems = await idbGetAllPrefixFilter(IDB_CONFIG.storeName, 'sg:')singaporeanItems is an array of 3 items that match the 'sg:' prefix argument.
(Using this colon delimited key format is the same as you'd use in valkey/redis.)
Have fun!
Credits
Gerry Gold
January 2026
