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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gxtech/indexeddb-util

v1.0.0

Published

IndexedDB的获取、增加、删除、查询

Downloads

8

Readme

IndexedDB 操作工具类

IndexedDB 操作工具类共返回10个方法,分别如下:

  • 初始化方法(init)
  • 添加数据方法(set)
  • 更新单条或多条数据方法(updateData)
  • 遍历数据表里所有的数据(getAllData)
  • 获取数据表里单条数据(getData)
  • 删除数据库(deleteDB)
  • 关闭数据库(closeDB)
  • 删除某一条记录(deleteData)
  • 删除存储空间全部记录(clearData)
  • 数据查询(searchData)

要调用其他方法必须先初始化数据库。总大小无限制,但因浏览器机制限制,单条数据大小不超过130M。

调用方式

npm 安装

npm install indexedDB

初始化方法

var dbObject = {
    dbName: 'userInfo', // 数据库名
    version: 1, // 版本号
    primaryKey: 'id', // 主键
    keyNames: [{ // 需要存储的数据字段对象
    	key: 'name', // 字段名
    	unique: false // 当前这条数据是否能重复 (最常用) 默认false
    }]
};

var userInfo = new IndexedDB(dbObject); 
userInfo.init();

添加数据方法

/**
* 添加数据
* @param {Array || Object} option 存入数据库的数据
*/

userInfo.set(option)

更新单条或多条数据方法

/**
* 更新单条或多条数据
* @param  {Array || object} option       更新的数据
* @return {[type]}              [description]
*/

userInfo.updateData(option)

遍历数据表里所有的数据

/**
* 遍历数据表里所有的数据
* @return {Array || Obiect}             返回数据表里所有的数据
*/

userInfo.getAllData()

获取数据表里单条数据

/**
* 获取数据表里单条数据
* @param  {String || Number} value        数据字段的值(按主键搜索)
* @return {[type]}              [description]
*/

userInfo.getData(valve)

删除数据库

/**
* 删除数据库
* @return {[type]}              [description]
*/
userInfo.deleteDB()

关闭数据库

/**
* 关闭数据库
* @return {[type]} [description]
*/
userInfo.closeDB()

删除某一条记录

/**
* 删除某一条记录
* @param  {String || Number} value        主键的值
* @return {[type]}              [description]
*/

userInfo.deleteData(valve)

删除存储空间全部记录

/**
* 删除存储空间全部记录
* @return {[type]}              [description]
*/

userInfo.clearData()

数据查询

/**
* 数据查询
* @param  {String} key          数据字段名
* @param  {String || Number} value        按字段查询的值
* @return {[type]}              [description]
*/
userInfo.searchData(key, value)

兼容性

Chrome、Edge、Firefox 、Internet Explorer9+、Opera、Safari