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

aomd-web-db

v1.0.1

Published

浏览器端 数据库操作助手

Downloads

1

Readme

webDB

  • 简易封装 接口均采用 Promise 一步操作
  • 支持 增删改查(以及模糊查询)
  • 使用 npm i aomd-web-db

events


| name | Parameters | Description | |:------------------|:----------:|:-----------------------------:| | init | ... | 初始化 | | upgradeneeded | ... | indexedDB 对应的upgradeneeded | | createObjectStore | ... | 创建存储表 | | deleteObjectStore | ... | 删除存储表 | | error | ... | 错误 | | get | ... | 取数据时 | | set | ... | 存数据时 | | del | ... | 删除数据时 | | clear | ... | 清楚表时 | | search | ... | 查询时 | | close | ... | 关闭数据库时 |

methods


| name | Description | |:------------------------------------------------------------------------------------------------------------------------------------------|:----------------------:| | getInstance(option?: WebDBOption): WebDB; | 单例获取 WebDB实例 | | init(): Promise; | 初始化 | | deleteDatabase(name: string): boolean; | 删除 indexedDB 库 | | createObjectStore(tableName: string, option?: CreateObjectStoreOption): IDBObjectStore; | 创建表 | | deleteObjectStore(tableName: string): boolean; | 删除表 | | getObjectStore(tableName: string, type?: transactionMode): IDBObjectStore; | 获取表事务操作 | | getIndexNames(tableName: string): DOMStringList | 获取所有 索引名称 | | saveKey(tableName: string, entity: any, key?: number | string): Promise<ReturnEntity>; | 通过 key 设置数据 | | getByKey(tableName: string, key: number | string): Promise<ReturnEntity>; | 通过 key 获取数据 | | getByIndexName(tableName: string, indexName: string, value: number | string): Promise<ReturnEntity>; | 通过 索引 获取数据 | | getByIndexNameAll(tableName: string, indexName: string, value: number | string, limit?: number): Promise<ReturnEntity>; | 通过 索引 获取所有数据 | | delByKey(tableName: string, key): Promise<ReturnEntity>; | 通过 索引 删除数据 | | clear(tableName: string): Promise<ReturnEntity>; | 清除单一表的所有数据 | | close(): Promise<ReturnEntity>; | 销毁 WebDB 实例 | | fuzzySearch(tableName: string, indexName: string, value: number | string): Promise<ReturnEntity>; | 模糊查询 | | on(eventName: EventName, cb: (en?: ReturnEntity) => unknown): void; | 监听事件 | | off(eventName: EventName, cb: (en?: ReturnEntity) => unknown): void; | 解除监听 |

model

WebDBOption

WebDBOption {
  name?: string;
  version?: number;
}

CreateObjectStoreOption

CreateObjectStoreOption {
  keyPath?: string;
  autoIncrement?: boolean;
}

ReturnEntity

ReturnEntity {
  // 调用事件
  eventName: string;
  // 调用表
  tableName: string;
  // 调用参数
  option: object;
  // 取出的数据
  entity: any;
}

example


//@ts-check
import { WebDB } from '../src/WebDB'

var db = WebDB.getInstance({ name: 'hiwebpage', version: 1 })

// db.deleteDatabase('hiwebpage')

db.on('upgradeneeded', () => {

    db.deleteObjectStore("test");

    // 创建一个表
    var objectStore = db.createObjectStore("test");

    // 此处最好取一样名称
    objectStore.createIndex("id", 'id')

    console.log('upgradeneeded')

})

db.init().then(() => {
    // 获取所有索引
    db.getIndexNames('test')

    // 根据下标进行创建 ro 更新
    db.saveKey('test', { name: 'xj', id: 4399 }, '5')
    db.saveKey('test', { name: 'xj2', id: 4399 }, '6')
    db.saveKey('test', { name: 'xj3', id: 4399 }, '7')
    db.saveKey('test', { name: 'xj4', id: '4399' }, '8')
    db.saveKey('test', { name: 'xj5', id: '4399' }, '9')

    // 更新 9 这个key
    db.saveKey('test', { name: 'xj2', id: 'id999' }, '9')


    // 自增长
    // db.saveKey('test', { id: 'xj1' })

    // 通过 key 获取单个
    db.getByKey('test', '8').then((data) => {
        console.error('getByKey', data.entity);
    })

    // 通过索引获取 一个 重复多个也取一个
    db.getByIndexName('test', 'id', 4399).then((data) => {
        console.error('getByIndexName', data.entity);
    })

    // 通过索引获取多个 limit可以筛选
    db.getByIndexNameAll('test', 'id', 4399).then((data) => {
        console.error('getByIndexNameAll', data.entity);
    })

    db.getByIndexNameAll('test', 'id', 4399, 1).then((data) => {
        console.error('getByIndexNameAll:limit:1', data.entity);
    })

    // 模糊查询
    db.fuzzySearch('test', 'name', 'x').then((data) => {
        console.error('fuzzySearch', data.entity);
    })

    // 根据key删除
    db.delByKey('test', '5').then((data) => {
        console.error('delByKey', data.entity);
    })

    // 清理表
    // db.clear('test')

})

示例图片