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

indexeddbhello

v2.0.1

Published

@hello

Downloads

84

Readme

// 初始化实例
import IndexedDBService from 'indexeddbhello';

// 所有操作都是异步的
const MyDataBase = new IndexedDBService('MyDataBase', 2);
MyDataBase.openDB('xxx')
或者
MyDataBase.openDB(['xxx','qqq',……]).then(res => {
    MyDataBase.putKeyData('xxx','key', 'value').then(res => {
        MyDataBase.getData('xxx', 'key').then(res => {
            ……
        })
    })
})
//  可以使用 async/await


   /**
     *
     * @param {string} dbName -数据库名称
     * @param {number} dbVersion -数据库版本
     */
 const MyDataBase = new IndexedDBService('MyDataBase', 2);

   /**
     * 打开或创建数据库   storeName存在就打开,不存在就创建
     * @param { string[] | string} storeName
     * @param {Object} options - 配置选项 可选。
     * @param {string} [options.keyPath] - 允许开发者指定对象存储区(ObjectStore)中的某个属性作为主键来存储和检索数据。当对象存储区被配置为使用内联键时,每个存储在对象存储区中的对象都必须包含这个指定的属性,并且这个属性的值必须是唯一的,以便作为主键来标识每个对象。
     * @param {boolean} [options.autoIncrement] - 这是一个布尔值,当设置为true时,并且没有提供keyPath或者keyGenerator,IndexedDB会自动为每个新对象生成一个唯一的键。这通常与keyPath一起使用,当keyPath指定的属性不存在或者其值为undefined时,会生成一个自动递增的键。
     * @param {number} [options.version] - 自定义 删除的时候使用
     * @returns
     */
    openDB(storeName, options = {})


	/**
     * 添加或更新数据
     * 自动生成key时使用这个添加更新
     * @param {string} storeName -存储区名称
     * @param { object } data -添加的值  key: value
     * @returns
     */
    putData(storeName, data)

   /**
    * 添加或更新数据
    * 手动填写key时使用这个添加更新
    * @param {string} storeName -存储区名称
    * @param {number | string} key -存储区名称
    * @param { object } data -添加的值  key: value
    * @returns
    */
    putKeyData(storeName, key, data) 

	 /**
     * 获取数据
     * @param {string} storeName -储存区名称
     * @param {string | number} key -为数据的key
     * @returns
     */
    getData(storeName, key)

	 /**
     * 删除数据
     * @param {string} storeName -储存区名称
     * @param {string | number} key -为数据的key
     * @returns
     */
    deleteData(storeName, key)

	/**
     * 删除对象存储区
     * @param {string} storeName -储存区名称
     * @returns
     */
    deleteObjectStore(storeName)

	/**
     * 删除数据库 静态方法直接通过类调用
     * @param {string} dbName -数据库名称
     * @returns
     */
    deleteDB(dbName)


// vue中使用
// 入口文件中初始化实例
import IndexedDBService from 'indexeddbhello';
// 创建数据库服务实例
async function infoDB() {
  try {
    const MyDataBase = new IndexedDBService('MyDataBase', 2);
    await MyDataBase.openDB('xxx');
    return MyDataBase;
  } catch (error) {
    console.error(error)
    return null;
  }
}

infoDB().then(res => {
  try {
    app.provide('MyDataBase', res);
  } catch (error) {
    console.error(error)
  } finally {
      app.mount('#app')
  }
})



// 页面中使用
const MyDataBase = inject("MyDataBase");

	await MyDataBase.openDB("xxx");

	let result = await MyDataBase.getData("xxx", key);

 	await MyDataBase.putKeyData("xxx", key, jsonData);