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

minordb

v0.1.3

Published

this is web-client database based on indexdb

Downloads

9

Readme

MinorDB

介绍

MinorDB 是基于 IndexDB 封装的 web 前端数据库,轻量,Promise语法使用简单,支持 jQuery , Vue , React等,支持typescript

安装与配置

npm 安装

npm install minordb

或者 browser 引入

//cdn
<script src="https://cdn.jsdelivr.net/npm/minordb/dist/minordb.min.js"></script>

配置

const dbConfig = {
    name: 'minorDbTest', //数据库名字
    version: 1,         //数据库版本
    //数据库的表配置
    schemas: {  
        user: '++id,username, &passsword, age',
        friends: 'name,age'
        message:'++id,from,to,msg'
    },
};

关于schemas

  • key : user,friends,message 分别对应一个 table(Store) 名字

  • value : 第一个字段是主键(值唯一),其他的是索引(~~非主键,非索引字段不用配置~~)

    • ++ ++代表是自增的主键(非必须,比如 friends.name非自增)
    • & 代表唯一索引,unique唯一不可重复

动态创建

创建,打开 minorDb


let minorDb = new MinorDB(dbConfig.name, dbConfig.version);
minorDb.open(dbConfig.schemas).then((event) => {}).catch(err => {});

使用说明

下面的语句若没有特殊注明,默认都是自动使用了事务,支持promise(async/await)

  1. insert

    可以直接使用 insert 方法插入一条或多条记录,支持promise

    //一条
    let user={ username: "1", password: '123', age: '1' }
    const result = await minorDb.user.insert(user)
    
    //多条
    const users = [
     { username: "2", password: '123', age: '1' },
     { username: "3", password: '123', age: '1' },
     { username: "4", password: '123', age: '1' }
    ];
    const result1 = await minorDb.user.insert(users)
    
  2. Find

    可以直接使用 getfind 方法获取一条或多条记录。

   //默认查询所有
   let users= await minorDb.user.find()
    

   //查询id>1的2条数据,升序排序
   //where 条件只能是 主键或索引
   let lUsers =minorDb.user.where({ id: { '>': 1 }).limit(2).sort(asc).find()

   //查询username=2的数据
   let lUsers =minorDb.user.where({ username: { '=': '3' }).find()
  1. update

    可以直接使用 update 方法更新数据库记录。

    const user = { id: 1, username: "1", password: '1234', age: '1' };
    //user数据需要包含主键
    let result = minorDb.user.update(user)

    //如果不包含主键,需要手动设置索引where
    let result = minorDb.user.where({password:{ =:"1"} }).update(user)
  1. remove

    可以直接使用 remove 方法删除数据库记录。


   //根据删除所有
   let result = minorDb.user.remove()
   //复杂的删除
   let result = minorDb.user.where({id:{'>':1,'<':3}}).remove()

遗留问题

where条件只支持 一个主键 或者 一个索引key查询

对于查询< > =条件受到indexDB官方IDBKeyRange 限制 只支持以下的组合形式

   All keys ≥ x	IDBKeyRange.lowerBound(x)
   All keys > x	IDBKeyRange.lowerBound(x, true)
   All keys ≤ y	IDBKeyRange.upperBound(y)
   All keys < y	IDBKeyRange.upperBound(y, true)
   All keys ≥ x && ≤ y	IDBKeyRange.bound(x, y)
   All keys > x &&< y	IDBKeyRange.bound(x, y, true, true)
   All keys > x && ≤ y	IDBKeyRange.bound(x, y, true, false)
   All keys ≥ x &&< y	IDBKeyRange.bound(x, y, false, true)
   The key = z