jsdb-tool
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

jsdb-tool插件使用说明

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

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

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

@Table({
    databaseName: "test", // 数据库名称
    tableName: "log", // 表名
    version: 1, // 当前版本号
    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;
}

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



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

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

// 删除当前表
dn.destroy(key: IDBValidKey | IDBKeyRange)

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

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

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

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

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

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

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i jsdb-tool

Weekly Downloads

0

Version

3.0.3

License

ISC

Unpacked Size

37.9 kB

Total Files

5

Last publish

Collaborators

  • wz-larry