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

dswda

v1.0.55

Published

web数据的存储方案,内置了 indexeddb 和 localstorage;支持 sql 语句,和反向转换 sql。可以自定义我们自己的 store 方案。自定义的 store 支持接收 sql 或者一个对象。dswda 会根据 store 接受的类型自动转换成对应的参数类型;

Downloads

43

Readme

dswda(Web data storage solution)

介绍

web数据的存储方案,内置了 indexeddb 和 localstorage;支持 sql 语句,和反向转换 sql。可以自定义我们自己的 store 方案。自定义的 store 支持接收 sql 或者一个对象。dswda 会根据 store 接受的类型自动转换成对应的参数类型;

安装

  # 通过npm下载
 npm i dswda -S

快速上手


let { initDB } = dswda

  let app = initDB({
      dname:'db4',
      tables:[
        {
          name:'tb1',
          primaryKey:'id',
          auto:true,
          fields:[{
            name:'id',
            unique:true,
            default:2,
            type:'varchar(10)'
          },{
            name:'name',
            unique:false,
            type:'string',
          },{
            name:'age',
            unique:false,
            type:'string'
          }],
        }
      ],
      version:1
    })


 let manager = app.exec()

console.log('this is dswda manager',maanger)

方法集合

| method | field | desc | | ------------ | ---------------------------------------- | ------------------------- | | initDB | qry::DataBase | 初始化存储 db | | createDB | qry::DataBase | 创建一个存储 db | | get | storeName:string | 通过一个 key 获取内容 | | set | {key:name,v:value} tip:个别 store 不支持 | 通过 key 设置 value | | dbList | none | 获取支持的 store 列表 | | delDb | dbName::string | 根据 store 名称删除 store | | updateDb | qry::DataBase | 更新 store | | openDb | dbName::string | 打开一个 store | | select | qry::(SelectType or string) | 查询数据 | | insert | qry::InsertType | 添加数据 | | update | qry::UpdateType | 更新数据 | | delete | qry::DeleteType | 删除数据 | | sql | sqlStr::string | 支持 sql 语法 | | version | qry::boolean | 获取当前 store 版本号 | | switchOrigin | storeName::string | 切换 store 源 |

type

方法中接收的类型

DataBase

| field | type | desc | required | | ------- | ------- | -------------- | -------- | | dname | string | 存储 db 的名称 | true | | tables | Table[] | store 的集合 | false | | version | boolean | 存储 db 的版本 | false |

Table

| field | type | desc | required | | ---------- | ------------ | ---------------- | -------- | | name | store 的名称 | 存储 db 的名称 | true | | fields | FieldMeta[] | store 的集合 | false | | primaryKey | boolean | 是否是唯一值 | false | | auto | boolean | 主键是否自动递增 | false |

FieldMeta

| field | type | desc | required | | ------------- | --------- | ---------------- | ------------------- | | name | string | 字段名 | true | | primaryKey | boolean | 是否是主键唯一值 | false default:false | | auto | boolean | 主键是否自动递增 | false default:false | | autoIncrement | boolean | 同 auto | false default:false | | unique | boolean | 是否是唯一值 | false default:false | | type | FieldType | 字段值存储类型 | false default:text | | notNull | none | - | false | | dataType | none | - | false | | default | none | - | false | | multiEntry | none | - | false | | enableSearch | none | - | false | | keyPath | none | - | false |

BaseQry

| field | type | desc | required | | ------- | ------------------ | ------------------------ | --------------------- | | order | 'asc' or 'desc' | 排序 | false default: 'desc' | | groupBy | string or string[] | 分组 | false | | having | object | 对查询的数据二次筛选条件 | false | | limit | number or number[] | 分页 | false | | where | WhereQry | 查询条件 | false |

SelectType extends BaseQry

| field | type | desc | required | | ------ | ------------------------------------ | ------------ | -------- | | from | string | 来源的 store | true | | fields | (FieldMeta[] or string or string[] ) | 查询的字段 | false |

InsertType

| field | type | desc | required | | ------ | ---------------- | -------------- | -------- | | into | string | 来源的 store | true | | values | InsertTypeMeta[] | 插入的一个数组 | true |

UpdateType extends BaseQry

| field | type | desc | required | | ----- | ---------------- | ------------ | -------- | | from | string | 来源的 store | true | | set | InsertTypeMeta[] | 修改的对象 | true | | where | WhereQry | 查询条件 | false |

DeleteType extends BaseQry

| field | type | desc | required | | ----- | -------- | ------------ | -------- | | from | string | 来源的 store | true | | where | WhereQry | 查询条件 | false |

InsertTypeMeta

{ [key: string]: any; }

WhereQry

WhereQryObj | WhereQryArray | string;

WhereQryArray

Array

WhereQryObj

{ [key: string]: WhereQryObj | string | WhereQryValueObj; }

WhereQryValueObj

| field | type | desc | required | | ----- | ------ | ------------- | -------- | | attr | string | 字段名称 | true | | value | any | 字段值 | false | | type | enum | 'and' or 'or' | false |

middleware

dswda 支持中间件,每次执行和完成后都会经过中间件的过滤。一个洋葱模型对象。

  • 稍后补充

plugin

dswda 支持插件,比如:增加日志插件,打点插件等;

  • 稍后补充

扩展 store

dswda 内置了 indexeddb 和 localStorerage;但是他并不仅仅只有这些。他对外提供了一些接口和抽象类。只要去继承他,并且实现这些方法,就可以手动开发一个我们自己的 store 数据管理存储库。 如果你不想继承这些接口或者抽象类,那么只要按照他的规范也可以。他是宽松的;有两种方式去开发我们自定义的 store

  • 开发一个 clalss 对象,并继承对外提供的 interface 或者 abstruct
  • 直接按照规范去实现这些方法即可;

稍后补充

开源协议

本项目基于 MIT,请自由的享受和参与开源。