npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@amateras/idb

v0.1.0

Published

Readme

amateras/idb

Usage

import 'amateras';
import 'amateras/idb';

// configure indexedDB
const idb = await $.idb('MyDB', 1)
// add store
.store('userStore', store => store
    .keyPath('id')
    .autoIncrement(true)
    // define store object type
    .schema<{
        id: number,
        name: string,
        age: number
    }>()
    .index('by_age', { keyPath: 'age' })
)
// open idb
.open();

// open `readwrite` transaction with `userStore`
const result = await idb.store('userStore', true, async store => {
    store.put({name: 'Amateras', age: 16});
    return store.getAll();
})

console.log(result); // [ { name: 'Amateras', age: 16, id: 1 } ]

Quick Examples

Get object from store

await idb.store('userStore', store => store.get(1))

Get all object from store

await idb.store('userStore', store => store.getAll())

Add object to store

Any changes to database without readwrite mode is resisted, pass true value to writable argument to enable readwrite mode.

await idb.store('userStore', true, store => store.add({name: 'Tsukimi', age: 16}))

Put object to store

The .put() method is different with .add() method, put object will replace the object of existed key.

await idb.store('userStore', true, store => store.put({name: 'Amateras', age: 17}))

Use index

await idb.store('userStore', true, store => store.index('by_age').getAll(16))

Operating multiple stores in one transaction

await idb.transaction(['userStore', 'itemStore'], true, async transaction => {
    transaction.store('itemStore').put({id: 2, name: 'Item 2'})
    return {
        users: await transaction.store('userStore').getAll(),
        items: await transaction.store('itemStore').getAll()
    }
})

Open cursor for advance operations

await idb.store('userStore', true, async store => {
    const teenagers = []
    await store.cursor(cursor => {
        if (cursor.value.age < 18) teenagers.push(cursor.value);
        cursor.continue();
    })
    return teenagers;
})

Upgrade Database

Using .upgrade() in $IDBStoreBuilder can set the store upgrade handle function to list. The store upgrade function is used for change object structure when the store is upgrading.

For example, in version 10:

{
    id: number,
    name: string
}

After version 11, we want to change the object structure:

{
    id: string,
    name: string,
    intro: string
}

You see the id is change to string type, and come with the new property intro. In the following example, we will upgrade this object structure, and this upgrade is only executed when client IDB version is lower than argument version.

store.upgrade(11, (objects) => {
    return objects.map({key, value} => {
        // since we didn't defined the object type in every different version,
        // the object is any type, please handle the upgrade carefully
        return { key,
            value: {
                ...value,
                id: value.id.toString(), // convert to string
                intro: `Hi, my name is ${object.name}` // add new intro property
            }
        }
    })
})

The upgrade function is set, this will be executed on $IDBBuilder.open().

[!NOTE] You should leave all the upgrade function in your codebase, unless you are sure the client database version is larger than this upgrade function.