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

@kbox/indexed-db

v1.0.4

Published

An indexedDB wrapper for accessing indexedDB as a promise base api implementation.

Downloads

11

Readme

indexed-db

An indexedDB wrapper for accessing indexedDB as a promise base api implementation.

Features

  • Create structure of database with indexes and version
  • Get model instances and query builder for both indexed columns and non indexed columns

Install

npm install @kbox/indexed-db
yarn add @kbox/indexed-db

Usage

import IndexedDb from "@kbox/indexed-db";

// 数据模型
const infoModel = {
 "name": "info",
 "columns": {
     "id": { "type": "int", "primary": true, "comment": "序号" },
     "name" : { "type": "string", "nullable": false, "comment": "名称" },
     "guid" : { "type": "string", "nullable": false, "unique": true, "default": "uuid", "comment": "唯一编号" },
     "size" : { "type": "int", "nullable": false, "defualt": 0, "comment": "文件大小" },
     "content" : { "type": "string", "nullable": false, "comment":"内容" },
     "is_deleted": { "type": "int", "nullable": false, "default": 0, "comment": "是否删除" },
     "is_disabled": { "type": "int", "nullable": false, "default": 0, "comment": "是否禁用" },
     "create_time" : { "type": "timestamp", "nullable": false, "default": "NOW", "comment": "创建时间" }
 }
}

// 数据集
const data = {
 name: "name",
 size: 10,
 content: "content"
};

// 创建数据库对象并初始化数据库模型
let db = new IndexedDb({
 namespace: "info_db",
 version: 1,
 models: [ infoModel ]
});

// 添加一条记录
await db.collection("info").insertOne(data).catch(err => console.error(err, data));

// 添加多条记录
await db.collection("info").insertMutil([data, data, data]).catch(err => console.error(err, data));

// 获取记录数量
await db.collection("info").count().catch(err => console.error(err, data));

// 查询编号为1的一条记录(没有用到索引,效率较低)
await db.collection("info").findOne({id: 1}).catch(err => console.error(err, data));

// 查询编号为1的一条记录(用到索引,效率较高)
await db.collection("info").findOneByKey(1).catch(err => console.error(err, data));

// 查询名称为“name”的一条记录(没有用到索引,效率较低)
await db.collection("info").findOne({name: "name"}).catch(err => console.error(err, data));

// 查询名称为“name”的所有记录(没有用到索引,效率较低)
await db.collection("info").find({name: "name"}).catch(err => console.error(err, data));

// 查询名称为“name”的所有记录(用到索引,效率较高)
await db.collection("info").findOneByUKey("name", "name").catch(err => console.error(err, data));

// 更新编号为1的记录
let updateData = { id:1, name: "new_name",  size: 100, content: "new_content"}
await db.collection("info").updateOne(updateData).catch(err => console.error(err, updateData));

// 删除编号为1的记录
await db.collection("info").removeOne(1).catch(err => console.error(err, data));

// 清空所有记录
await db.collection("info").truncate().catch(err => console.error(err, data));

// 删除数据库
await db.remove().catch(err => console.error(err));

/****************
 * 
 * 高级查询
 * 
 ****************/

// 集合记录的高级查询方法,用于获取集合的记录。
// 获取全部记录
await db.collection("info").queryVlues().catch(err => console.error(err, data));
// 获取所有符合指定主键或 IDBKeyRange 的记录
await db.collection("info").queryVlues(query).catch(err => console.error(err, data));
// 指定获取记录的数量
await db.collection("info").queryVlues(query, count).catch(err => console.error(err, data));


// 集合记录的高级查询方法,用于获取所有符合条件的主键。
// 获取所有记录的主键
await db.collection("info").queryKeys().catch(err => console.error(err, data));
// 获取所有符合条件的主键
await db.collection("info").queryKeys(query).catch(err => console.error(err, data));
// 指定获取主键的数量
await db.collection("info").queryKeys(query, count).catch(err => console.error(err, data));

Testing

npm run test

License

MIT