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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jsdb-tool

v4.0.1

Published

js indexdb封装库

Readme

jsdb-tool插件使用说明

本插件是wz-js-db得增强,wz-js-db后续不在维护,使用wz-js-db项目可以切换至jsdb-tool

import { BaseUtil, Table, PrimaryKey, IndexKey, CreateTime, UpdateTime, Storage, ExpireTime, DbUtil } from "jsdb-tool";

// Storage为BaseUtil的同步实现,使用方式同BaseUtil,但不支持mode为db的情况

//DbUtil为数据库操作类具有以下静态方法
DbUtil.getDbList() // 获取数据库列表
DbUtil.getDbDet(databaseName) // 获取数据库详情
DbUtil.getDb(databaseName) // 获取数据库实例
DbUtil.deleteTable(databaseName, tableName) // 删除表
DbUtil.deleteDatabase(databaseName) // 删除数据库


@Table({
    databaseName: "test", // 数据库名称
    tableName: "log", // 表名
    mode: "db", // 数据库类型 'db' | 'localStorage' | 'sessionStorage'
})
class LogDb extends BaseUtil {
    
    // 构造函数优先
    constructor({
        databaseName: "test", // 数据库名称
        tableName: "log", // 表名
        version: 1, // 当前版本号
        mode: "db", // 数据库类型 'db' | 'localStorage' | 'sessionStorage'
    }) {

    }

    // 主键
    @PrimaryKey()
    id;

    // 索引
    @IndexKey()
    dateTime;

    // 数据插入时间
    @CreateTime()
    createTime;

    // 数据更新时间
    @UpdateTime()
    updateTime;

    // 数据过期时间(毫秒数)
    @ExpireTime()
    exTime;
}

// 实例化数据库, 实例所有方法均返回promise
const db = new LogDb()



//新增数据 flag 是否存在更新不存在则新增
db.insert(data: any, flag = true) 

// 修改数据
db.update(data: any)


//清空当前表
db.clear()

// 查询当前表数据总数
db.count()

// 根据主键删除当前表数据 key -  主键
db.delete(key)

//根据索引删除数据 index -  索引, val索引对应的值(可选)
db.deleteByIndex(index: string, val: IDBValidKey | IDBKeyRange)

//根据主键查询当前表数据 key -  主键或索引键  
db.findById(key: IDBValidKey | IDBKeyRange)

//根据索引查询当前表数据 index -  索引, val索引对应的值(可选)
db.findByIndex(index: string, val: IDBValidKey | IDBKeyRange)

// 查询当前表所有数据
db.findAll()

// 分页查询数据 current -  当前页 size - 每页条数
db.selectPage(current?: number = 1, size?: number = 10)

const tmp = [
    {
        taskIdTX: 1,
        dateTime: '13',
        taskLocationId: '11',
    },
    {
        taskIdTX: 2,
        dateTime: '12',
        taskLocationId: '1',
    },
    {
        taskIdTX: 3,
        dateTime: '166',
        taskLocationId: '1', 
    },
    {
        taskIdTX: 33,
        dateTime: '16',
        taskLocationId: '1',
    },
    {
        taskIdTX: 4,
        dateTime: '17',
        taskLocationId: '2', 
    }
]

const tt = [
    {
        dateTime: '12', 
        age: '123',
        name: '123',
        xx: '11',
        yy: '13',
    },
    {
        dateTime: '13', 
        age: '33',
        name: '44',
        xx: '55',
        yy: '66',
    }
]
// 1.条件查询
db.select(['taskLocationId', 'dateTime as dt']).get()

查询结果
[
    {"taskLocationId":"11","dt":"13"},
    {"taskLocationId":"1","dt":"12"},
    {"taskLocationId":"1","dt":"166"},
    {"taskLocationId":"2","dt":"17"},
    {"taskLocationId":"1","dt":"16"}
]


// 2.条件查询
db.select(['taskLocationId', 'dateTime as dt']).groupBy(['taskLocationId']).get()

查询结果
[
    {
        "taskLocationId":"11",
        "children":[
            {"taskLocationId":"11","dt":"13"}
        ]
    },
    {  
        "taskLocationId":"1",
        "children":[
            {
                "taskLocationId":"1","dt":"12"
            },
            {
                "taskLocationId":"1","dt":"166"
            },
            {   
                "taskLocationId":"1","dt":"16"
            }
        ]
    },
    {
        "taskLocationId":"2",
        "children":[{"taskLocationId":"2","dt":"17"}]
    }
]

// 3.条件查询
db.groupBy(['taskLocationId'])
    .select([
        'taskLocationId as id', 
        'count(dateTime) as count',
        'dateTime as dt',
        'sum(dateTime) as sum',
        'min(dateTime) as min',
        'max(dateTime) as max',
        'avg(dateTime) as avg',
        'concat(dateTime) as dtstr',
    ])
    .get()

查询结果
[
    {
        "id":"11",
        "count":1,
        "sum":13,
        "min":13,
        "max":13,
        "avg":13,
        "dtstr":"13",
        "children":[
            {
                "dt":"13",
                "id":"11"
            }
        ]
    },
    {
        "id":"1",
        "count":3,
        "sum":194,
        "min":12,
        "max":166,
        "avg":64.66666666666667,
        "dtstr":"12、166、16",
        "children":[
            {
                "dt":"12",
                "id":"1"
            },
            {
                "dt":"166",
                "id":"1"
            },
            {
                "dt":"16",
                "id":"1"
            }
        ]
    },
    {
        "id":"2",
        "count":1,
        "sum":17,
        "min":17,
        "max":17,
        "avg":17,
        "dtstr":"17",
        "children":[
            {
                "dt":"17",
                "id":"2"
            }
        ]
    }
]

// 4.条件查询
db.select(['dateTime'])
    .leftJoin(tt, 'dateTime')
    .get()

查询结果
[
    {"dateTime":"13","age":"33","name":"44","xx":"55","yy":"66"},
    {"dateTime":"12","age":"123","name":"123","xx":"11","yy":"13"},
    {"dateTime":"166"},
    {"dateTime":"17"},
    {"dateTime":"16"}
]

// 5.条件查询
db.groupBy(['taskLocationId'])
    .select(['dateTime'])
    .innerJoin(tt, 'dateTime')
    .get()

查询结果
[
    {"dateTime":"13","age":"33","name":"44","xx":"55","yy":"66"},
    {"dateTime":"12","age":"123","name":"123","xx":"11","yy":"13"}
]