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

@weijunfu/fu-db

v1.1.8

Published

基于indexedDB进行封装的便捷操作库

Downloads

4

Readme

fu-db

基于IndexedDB进行封装的简易库

Install 安装

npm install @weijunfu/fu-db@latest
// or
yarn add @weijunfu/fu-db@latest
// or
pnpm install @weijunfu/fu-db@latest

Use 使用

import FuDB from '@weijunfu/fu-db'

批量创建存储

创建名为fu-db的数据库,同时创建三个存储表user、role、menu,并创建名为name的索引

await FuDB.createStore(
    'fu-db',
    1,
    [
        { storeName: 'user', storeOption: { keyPath: 'uid', autoIncrement: true }, indexOption: [{ indexName: "name", indexOption: { unique: false } }] },
        { storeName: 'role', storeOption: { keyPath: 'rid', autoIncrement: true }, indexOption: [{ indexName: "name", indexOption: { unique: false } }] },
        { storeName: 'menu', storeOption: { keyPath: 'mid', autoIncrement: true }, indexOption: [{ indexName: "name", indexOption: { unique: false } }] }
    ]
)

若基于上述再创建存储dept, 数据库版本应该变为2

await FuDB.createStore(
    'fu-db',
    2,
    [
        { storeName: 'dept', storeOption: { keyPath: 'dept_id', autoIncrement: true }, indexOption: [{ indexName: "name", indexOption: { unique: false } }] },
    ]
)

添加数据

添加单条数据

const db = new FuDB(dbName, storeName, version);
await db.init()

db.add({
    name: 'ijunfu', 
    email: '[email protected]', 
    age: Math.floor(Math.random()*100), 
    gender: Math.random() < 0.5 ? 1 : 0
})

db.close()

批量添加数据

批量向存储中添加数据

await db.addBatch([
    { name: 'ijunfu', email: '[email protected]', age: 18, gender: 1 },
    { name: 'wei', email: '[email protected]', age: 16, gender: 1 },
    { name: 'junfu', email: '[email protected]', age: 20, gender: 0 }
])

根据id获取数据

根据keypath获取数据

const user = await db.get(1)

修改数据

根据keypath修改数据

await db.update({
    id: 1,
    name: 'weiijunfu', 
    email: '[email protected]', 
    age: Math.floor(Math.random()*100), 
    gender: Math.random() < 0.5 ? 1 : 0
})

删除数据

删除删除指定keypath的数据

await db.delete(1)

获取所有数据

查询存储中所有的数据

const data = await db.getAll()

根据索引查询数据

查询名称为ijunfu的数据

const data = await db.queryByIndex('name', 'ijunfu');

查询指定范围的数据

查询年龄范围在[10,20]的数据

await db.queryByRang('age', 10, 20)

复合查询

先根据性别筛选出数据,再根据姓名筛选出符合条件的数据

await db.queryByCondition('gender', 1, 'name', '王五')

获取版本信息

获取数据库版本信息 若数据库不存在,则创建数据库,返回版本号为1 若数据库存在,则直接返回当前版本号

await FuDB.getVersion('fu-db').then(res => console.log('db version', res)).catch(err => console.error('db version', err));

删除数据库

根据数据库名称删除指定数据库

FuDB.deleteDatabase('fu-db')

删除存储

删除以user命名的存储

await FuDB.deleteStore('fu-db', 'user', 2)

判断存储/表名是否存在

user存储/表名是否存在

await FuDB.existStore('fu-db', 'user')