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

@wbiokr/indexdb

v1.1.0

Published

基于 IndexedDB 的轻量级前端数据库封装库

Downloads

140

Readme

@wbiokr/indexdb

基于 IndexedDB 的轻量级前端数据库封装库

安装

npm install @wbiokr/indexdb

引入

// ESM
import WbiokrDB from '@wbiokr/indexdb';

// CJS
const WbiokrDB = require('@wbiokr/indexdb');

直接在浏览器中使用(打包后的文件在 dist 目录下):

<script src="./dist/bundle.cjs.js"></script>

初始化

const db = WbiokrDB(dbName, version, storeName, keyPath);

参数说明

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | dbName | string | DB-${location.host} | 数据库名称 | | version | number | 1 | 数据库版本号 | | storeName | string | STORE-${location.host} | 对象仓库名称 | | keyPath | string | id | 主键字段名 |

API

1. 插入/更新数据

db(key, data)
  • 参数:
    • key: 主键值
    • data: 要存储的数据(对象)
  • 返回: Promise
// 示例
await db(1, { name: '张三', age: 25 });
await db('user1', { username: 'test', email: '[email protected]' });

2. 查询单条数据

db(key)
  • 参数:
    • key: 主键值
  • 返回: Promise,解析为存储的数据对象
// 示例
const user = await db(1);
console.log(user); // { name: '张三', age: 25 }

3. 查询所有数据

db()
  • 参数: 无
  • 返回: Promise,解析为包含所有数据的数组
// 示例
const allData = await db();
console.log(allData); // [{ id: 1, data: {...} }, { id: 2, data: {...} }]

4. 删除指定数据

db.remove(key)
  • 参数:
    • key: 主键值
  • 返回: Promise
// 示例
await db.remove(1); // 删除主键为 1 的数据

完整示例

import WbiokrDB from '@wbiokr/indexdb';

// 初始化数据库
const db = WbiokrDB('myDB', 1, 'users', 'id');

// 插入数据
await db(1, { name: '张三', age: 25 });
await db(2, { name: '李四', age: 30 });

// 查询单条
const user = await db(1);
console.log(user); // { name: '张三', age: 25 }

// 查询所有
const allUsers = await db();
console.log(allUsers);

// 删除数据
await db.remove(1);

// 也可以只传入部分参数使用默认值
const defaultDb = WbiokrDB(); // 使用默认配置

浏览器兼容性

  • Chrome/Edge/Firefox/Safari/Opera 最新版
  • 支持 IndexedDB 的现代浏览器
  • 兼容 window.indexedDBwindowwebkitIndexedDBwindow.mozIndexedDBwindow.msIndexedDB

License

MIT