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

@styleofpicasso/indexdb

v0.0.2

Published

a plugin of indexedDB service

Downloads

6

Readme

1. 安装 与 引入
// 安装 
npm install @styleofpicasso/indexdb --save-dev
或
yarn add @styleofpicasso/indexdb

// 引入
import IdxDB from '@styleofpicasso/client';
2. 使用案例
// 使用案例
import IdxDB from '@styleofpicasso/client';

const indexdb = new IdxDB(databaseName, storeName, keyPath, [{name, prop, {unique: false}}])

indexbd.create(() => {
  console.log('创建成功')
})
3. 详细说明
  • 安装
npm install @styleofpicasso/indexdb --save
  • 引用
import IdxDB from '@styleofpicasso/indexdb'

/**
 * @description 创建(获取)服务的实例 
 * @param databasename  数据库名称
 * @param storename  仓库表名称
 * @param keyPath  主键
 * @param conf 生成索引的配置信息 包含: {name, prop, conf}  name: 索引名称, prop: 索引对应保存的属性 (name 与 prop 一致), conf: 是否可重复 {unique: false}, 不可
 * /

const indexdb = new IdxDB(databasename, storename, keyPath, conf)
// 例如:
const indexdb = new IdxDB('ithinkdt, 'jt', 'id', {name: 'name', prop: 'name', conf: {unique: false}})
  • 功能
|—— 创建 或 打开数据库  // create()
|—— 新增数据  // add()
|—— 更新数据  // update()
|—— 读取数据  // read()
|—— 遍历所有数据  // readAll()
|—— 删除数据  // remove()
|—— 清空数据  // clear()
|—— 根据索引读取数据  // readByIndex()
|—— 关闭数据连接  // close()
|—— 删除仓库表  // deleteObjectStore()
|—— 删除数据库  // deleteDatabase()
  • API 具体的使用
  1. create(succFn, failFn)
/**
 * @description 新建 或 打开数据库 (后续对表的操作都是再打开数据库之后)
 * @param succFn 成功之后的回调
 * @param failFn 失败的回调
 * /

// 打开数据库
indexdb.create(() => {
    console.log('打开成功')
    // 新增
    indexdb.add({id: 1, name: '张三', ageL 10})
    // 更新
    indexdb.update({id: 1, name: 'lisi', age: 10}, {id: 2, name: 'wangwu', age: 18})
    // 读取
    indexdb.read([1, 2], (id, data) => {
        console.log(id, data)
    }, (result) => {
        console.log(result)
    })
    // 遍历读取
    indexdb.readAll((result) => {
        console.log(result)
    })
    // 通过索引读取数据
    indexdb.readByIndex('name', ['lisi', 'wangwu'], (name, data) => {
        console.log(name, data)
    }, (result) => {
        console.log(result)
    })
    // 删除数据
    indexdb.remove(1)
    // 清空表数据
    indexdb.clear(() => {
        console.log('清空成功')
    })
    // 断开连接
    indexdb.close()
})

// 删除仓库表
indexdb.deleteObjectStore(() => {
    console.log('删除成功')
})

// 删除数据库
indexdb.deleteDatabase(() => {
    console.log('删除成功')
})
  1. add(data, cb)
/**
 * @description 新增数据,如果主键相同会报错
 * @param data: array||object,
 * @param cb: 回调 (当data不存在时调用)
 * /
// 使用见 1
  1. update(data, cb)
/**
 * @description 更新数据
 * @param data: array || object
 * @param cb: 回调 (当data不存在时调用)
 * /
使用见 1
  1. read(list, progressFn, complateFn)
/**
 * @description 读取数据
 * @param list: 需要读取的数据的主键值的集合
 * @param progressFn: 每个主键值读取成功的回调 参数:主键值, 读取的结果
 * @param complateFn: 当所有的都读取完的回调  参数: 读取的结果的集合
 * /
使用见 1
  1. readAll(complateFn)
/**
 * @description 遍历读取数据
 * @parame complateFn: 读取完数据的回调
 * /
使用见 1
  1. readByIndex(indexName, list, progressFn, complateFn)
/**
 * @description 通过索引读取数据
 * @param indexName: 当前使用的索引名称
 * @param list: 索引名称值的集合
 * @param progressFn: 每个索引值读取数据成功的回调 参数:索引值, 读取的数据
 * @param complateFn: 所有索引读取完的回调  参数: 读取完数据的结果集合
 * /
使用见 1
  1. remove(data, cb)
/**
 * @description 删除数据
 * @param data: Array || object  需要删除的主键值的集合
 * @param cb: 回调  (当data不存在时调用)
 * /
使用见 1
  1. clear(cb)
/**
 * @description 清空表数据
 * @parame cb: 当清除成功之后的回调
 * /
使用见 1
  1. close()
/**
 * @description 断开连接
 * /
使用见 1
  1. deleteObjectStore(cb) (关系: 他与create() 方法平级)
/ **
  * @description 删除仓库表
  * param cb 删除成功的回到函数
  * /
indexdb.deleteObjectStore(() => {
    console.log('删除成功')
})

也可参阅 1
  1. deleteDatabase(succ, fail) (关系: 它与create() 方法平级)
/**
 * @description 删除数据库
 * @param succ: 成功的回到函数
 * @param dail: 失败的回到
 * /
indexdb.deleteDatabase(() => {
    console.log('删除成功')
})
也可参阅 1