@lubankit/indexeddb
v1.0.1
Published
indexdb
Readme
IndexedDB
A simple wrapper around IndexedDB that provides a convenient interface for interacting with the database.
Usage
IndexedDB.onupgradeneeded = (db) => {
// Create an object store named 'users' with 'id' as the key path and auto-increment enabled
if (!db.objectStoreNames.contains('users')) {
db.createObjectStore('users', { keyPath: 'id', autoIncrement: true })
}
}
const db = new IndexedDB({dbName, version})
const command = await db.getCommand()
// Insert a new record into the 'users' object store
await command.add('users', { id: 1, name: 'Alice' })
// Delete a record from the 'users' object store by its key
await command.delete('users', 1)
// Update a record in the 'users' object store
await command.update('users', { id: 1, name: 'Bob' })
// Query a record from the 'users' object store by its key
const user = await command.queryOne('users', 1)
// Query all data from the 'users' object store
const list = await command.queryAll('users')