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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-wrap-indexed-db

v0.0.10

Published

Promise based wrapper for IndexedDB provide easiest way for interacting with database

Downloads

11

Readme

Simple wrap for IndexedDB

Promise based wrapper for IndexedDB provide easiest way for interacting with database

import Connection from 'simple-wrap-indexed-db';
import Database from 'simple-wrap-indexed-db';

const DB_NAME = `my_first_db`;
const STORAGES = [
    { name: `users` },
    { name: `images` }
];

(async () => {
    const connection = await Connection.create(DB_NAME, STORAGES);
    const database = new Database(connection);

    await database.storage(`users`).insert({ name: `Max`, rating: 9 });
    
    // { id: 1 name: `Max`, rating: 9 }
    const user = await database.storage(`users`).find(1);
    user.rating = 5;

    await database.storage(`users`).update(user);
    
    await database.storage(`users`).insertBatch([
        {name: `Alex`, rating: 4},
        {name: `Anna`, rating: 8},
        {name: `Jane`, rating: 1},
        {name: `Donald`, rating: 9},
    ]);

    const result = await database.storage(`users`).filter(user => user.rating > 5).get();
    // [{id: 3, name: `Anna`, rating: 8}, {id: 5, name: `Donald`, rating: 9}]
    result.items;

    const usersIdsToDelete = result.items.map(user => user.id);

    await database.storage(`users`).deleteBatch(usersIdsToDelete);

    const result2 = await database.storage(`users`).get();
    // [
    //     { id: 1 name: `Max`, rating: 9 },
    //     { id: 2, name: `Alex`, rating: 4 },
    //     { id: 4, name: `Jane`, rating: 1 },
    // ]
    const users = result2.items;
    users.forEach(user => user.rating = 10);

    await database.storage(`users`).updateBatch(users);

    const result3 = await database.storage(`users`).limit(2).desc().get();
    // [{ id: 4, name: `Jane`, rating: 10 }, {id: 2, name: `Alex`, rating: 10}]
    result3.items;
})();

Connection

Connection provide simple promise based feature for connecting to db and can automatic detect current version, increase it and create new storages

Create database

Connection.create method will create db with databaseName if it is not exists.

If database already exists Connection.create will check diff of it current storages with list in second argument storagesList. In case of new storages which are in storagesList but not exists in current db - method will increase db version and create new storages. If diff show nothing - method just make connection to current db version

Connection.create(databaseName, storagesList)

Storage

Database.storage method return an instance of class Storage which provide simple way for manipulating data from IDBObjectStore

Query builder

Storage implemented DatabaseStorageInterface all methods of which will return QueryBuilderInterface. For executing query you need to call method QueryBuilderInterface.get

const database = new Database(connection);

const usersGenerator = async function*(){
    do {
        const limit = 5;
        let offset = 0;

        let result = await database.storage(`users`)
            .filter(user => user.age >= 18 && user.sex === `male`)
            .limit(limit)
            .offset(offset)
            .get();
        
        yield result.items;
        offset += limit;
    } while (result.qty === limit);
};

for (let users of usersGenerator()) {
    console.log(users);
}