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

r-indexdb

v0.0.1

Published

indexdb的操作工具

Downloads

5

Readme

indexDb 增删改查工具

快速上手

使用 npm 包

npm i r-indexdb -S

在函数中使用

import RIndexDb from 'r-indexdb';
const dbInst = new RIndexDb('dbName',[{name:'tbName',keyPath:'id'}])

async function findById(id){
    await dbInst.ready();
    const ret = await dbInst.findByPk('tbName',id);
    return ret;
}

使用方式

在使用该工具进行增删改查之前,需要先调用 await dbInst.ready()方法等待初始化完毕。

API

获取实例

const dbInst = new RIndexDb(databaseName: string,tbConfigs?: TbConfig[], dbVersion?: number,);

databaseName // 新建或者打开的库名
dbVersion // 库版本号默认为 1
tbConfigs // 库中需要使用的表的配置。

interface TbConfig {
    name: string; // 表名
    autoIncrement?: boolean; // 是否自增主键
    keyPath?: string; // 主键字段
    indexs?: IndexConfig[]; // 表索引配置
}

interface IndexConfig {
    name: string; // 索引名,不能重复
    prop: string; // 在存储对象上的那个属性上建立索引,可以是一个单个的key值,也可以是一个包含key值集合的数组
    config?: {
        unique: boolean; // 用来指定索引值是否可以重复,为true代表不能相同,为false时代表可以相同
        multiEntry: boolean; // 当第二个参数keyPath为一个数组时,如果multiEntry是true,则会以数组中的每个元素建立一条索引,如果是false,则以整个数组为keyPath值,添加一条索引
}

新增数据

1、单条新增数据createcreate(tbName: string, data: any): Promise<unknown>; 2、批量新增数据bulkCreatebulkCreate(tbName: string, datas: any[]): Promise<unknown>; 3、通过主键查找数据findByPkfindByPk(tbName: string, keyPath: string): Promise<unknown>; 4、通过索引查找数据findByIndexfindByIndex(tbName: string, indexName: string, keyPath: string): Promise<unknown>; 5、通过函数过滤查找数据queryquery(tbName: string, filter?: (item: any) => boolean): Promise<unknown>; 6、通过主键来更新数据updateupdate(tbName: string, data: any): Promise<unknown>; 7、通过主键删除数据deletedelete(tbName: string, keyPath: string): Promise<unknown>; 8、如果无法通过主键来更新和删除数据,可以使用 forEachcursor进行操作。 forEach(tbName: string, callback: (cursor: any) => void): Promise<unknown>;

使用cursor.value拿到数据.
使用cursor.updata()更新数据.
使用cursor.delete()删除数据.
使用cursor.continue()读取下一条数据.

9、新增表createStore createStore(tbName: string, tconfig?: Omit<TbConfig, "name">): IDBObjectStore | undefined; 10、新增索引createIndexcreateIndex(tb: string | IDBObjectStore | undefined, index: IndexConfig): boolean; 11、删除表中所有数dropStoredropStore(tbName: string): Promise<unknown>;