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

aiv367-idb

v1.0.0

Published

一个indexedDB库,包含常用的增删改查等方法

Downloads

5

Readme

aiv367-idb

介绍

indexedDB库,包含常用的增删改查方法

Gitee

https://gitee.com/aiv367/aiv367-idb

示例

http://aiv367.gitee.io/aiv367-idb/demo

安装

npm i aiv367-idb --save

使用

初始化创建仓库及索引
import IDB from 'aiv367-idb';


/*
new IDB('demoDataBase', 1, {
    onupgradeneeded: (evt) => {},
    onsuccess: (evt) => {},
    onerror: (evt) = {},
    onblocked: (evt) => {},
};
*/
let idb = new IDB('demo', 1, {

    onupgradeneeded(evt) {

        const db: IDBDatabase = (evt.target as IDBOpenDBRequest).result;

        if (!db.objectStoreNames.contains('book')) {
            let objectStore = db.createObjectStore('book', { keyPath: 'id', autoIncrement: true });
            objectStore.createIndex('id', 'id', { unique: true });
            objectStore.createIndex('type', 'type', { unique: false });
        }

    }

});
添加一条数据
// 数据不带主键
idb.store('book').add({ name: 'book11', type: 'story' }).then(res => console.log(res));

// 数据中带主键
idb.store('book').add({ id: 1, name: 'book11', type: 'story' }).then(res => console.log(res)); 

// 通过第二个参数传递主键
idb.store('book').add({ name: 'book11', type: 'story' }, 1).then(res => console.log(res)); 
添加多条数据
idb.store('book').adds([
    { name: 'book11', type: 'story' },
    { name: 'book12', type: 'history' },
    { name: 'book13', type: 'history' },
    { name: 'book14', type: 'story' }
]).then(res => console.log(res));
修改数据
// 根据数据中主键查找数据并修改数据
idb.store('book').update({ id: 1, name: 'book22', type: 'story' }).then(res => console.log(res)); 

// 通过第二个参数传递主键,查找要修改的数据
idb.store('book').update({ name: 'book22', type: 'story' }, 1).then(res => console.log(res)); 
删除数据
// 根据主键删除数据
idb.store('book').delete(1).then(res => console.log(res));

// 通过 IDBKeyRange 对象删除数据
// IDBKeyRange API: https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange
idb.store('book').delete(IDBKeyRange.only(1)).then(res => console.log(res)); 

// 通过回调函数删除多个数据, 回调函数返回 true, 该条数据被删除
idb.store('book').delete(data => data.name === 'book2').then(res => console.log(res)); 
获得一条数据
// 根据主键获得数据
idb.store('book').get(1).then(res => console.log(res));

// 通过 IDBKeyRange 对象获得数据
idb.store('book').get(IDBKeyRange.only(1)).then(res => console.log(res)); 

// 通过回调函数获得数据
idb.store('book').get(data => data.name === 'book2').then(res => console.log(res)); 
获得多条数据
// 返回全部数据
idb.store('book').gets().then(res => console.log(res));

// 通过 IDBKeyRange 对象获得多条数据
idb.store('book').gets(IDBKeyRange.bound(1, 10)).then(res => console.log(res)); 

// 通过回调函数获得多条数据
idb.store('book').gets(data => data.id <= 10).then(res => console.log(res)); 
使用索引获得数据
idb.store('book').index('type').gets().then(res => console.log(res));
idb.store('book').index('type').gets(IDBKeyRange.only('story')).then(res => console.log(res)); 
idb.store('book').index('type').gets(data => data.type === 'story').then(res => console.log(res));
获得符合条件的数据数量
idb.store('book').count(IDBKeyRange.only('story')).then(res => console.log(res));
idb.store('book').count(data => data.type === 'story').then(res => console.log(res));
清空一个仓库数据
idb.store('book').clear();
获得 IDBDatabase 对象
idb.db.then(db => {
    // db: IDBDatabase
});
删除数据库
idb.deleteDataBase(); //删除当前IDB实例访问的数据库
// or
IDB.deleteDataBase('book') //通过IDB的静态方法删除任意数据库
关闭当前访问的数据库
idb.closeDataBase();