1 Star 0 Fork 0

x135356 / wxDB

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

wxDB

介绍

基于微信数据库api打包的,数据库管理。相对方便的创建和管理你的“微信云数据库”

软件架构

软件架构说明

安装教程

  1. npm install wx-db --save //安装到项目

  2. 打开微信开发工具,选择云开发,创建环境id,如:a123

  3. 打开微信开发工具,选择云开发,选择数据库,创建数据集合如:Abc

  4. 创建一个类继承 如model/AbcDB.js:

        import DB from 'wx-db'
    
        class AbcDB extends DB {
            constructor(name,env)
            {
                super('Abc',env); //Abc是数据集合的名称,env是环境id默认为:a123
            }
        }
    
        AbcDB = new AbcDB();
        export {AbcDB};
  5. 如有必要请注意设置集合的权限,也是在云开发工具里设置,默认每一个微信用户能get到的,都是它自己set的数据

  6. 可以反复前面3-4步那样,创建无数个集合和类继承

使用说明

  1. 引入【安装第4步】创建的类:

    import {AbcDB} from '@/model/AbcDB'
  2. 使用缓存:

     AbcDB.setStorage(key,val).then(); //创建AbcDB集合缓存
     AbcDB.getStorage(key).then(res=>{console.log(res);}); //获取AbcDB集合缓存
     AbcDB.deleteStorage(key) //删除AbcDB集合指定缓存
     AbcDB.deleteStorageAll() //删除AbcDB集合全部缓存
  3. 创建:

     AbcDB.create({money:14,time:2019}) //创建一条数据,字段键分别为money,time值分别为14,2019

    数据捕捉:

     完整示例:AbcDB.find(id).get().then(res=>{console.log(res);}); //以find()捕捉到数据后,由get()输出捕捉到的数据,then()为异步成功后执行的结果(后面除了可以拼接get()也可以拼接如update,delete...)
     AbcDB.find(id) //以id捕捉,不单独使用,可配合像上面的方式使用
     AbcDB.all() //捕捉Abc集合的所有数据
     AbcDB.where() //以指定条件捕捉(不支持openid,它由微信云数据库的权限那里操作)
         AbcDB.where('money',14) //捕捉如:money等于14的数据,如需获取AbcDB.where('money',14).get().then(res=>{console.log(res);});
         AbcDB.where('money','>',14) //捕捉如:money大于14的数据,除了大于还支持如:'>','<','!=','<=','>='
         AbcDB.where('money','in',[10,20]) //捕捉如:money为10或20的数据
         AbcDB.where('money','nin',[10,20]) //捕捉如:money不是10和20的数据
         AbcDB.where('money','&',['<',15],['>',12]) //特殊:money小于15与大于12的数据
         AbcDB.where('money','>',10).where('time','<',2019) //钱大于10,时间小于2019的数据
     AbcDB.orWhere().get().then(res=>{console.log(res);}); //调用方式与where一样,暂时只支持get

    数据获取get:

     AbcDB.where('money',14).get().then(res=>{console.log(res);}); //前面捕捉到数据之后,在后面加get就可以获取它们
     AbcDB.where('money',14).select(['name','time']).then(res=>{console.log(res);}); //获取部分字段键与它们的值

    数据自增:

     AbcDB.find('123456789').increment('money',2).then(res=>{console.log(res);}); //捕捉id为123456789的那条数据,将它的字段键为money的值自增2,如果原来money键的值为14自增2之后它的值变成:16

    排序:

     AbcDB.where('money','>',14).orderBy('time','asc') //捕捉money大于14的所有数据,以time升序排序
     AbcDB.where('money','>',14).orderBy('time','desc') //同上,降序排序

    局部更新数据:

     AbcDB.find('123456789').update({money,17}) //捕捉id为123456789的那条数据,将它的money的值改成17,其它键的值不变

    整条更新:(不建议用来修改数据)

     AbcDB.find('123456789').set({money,17}) //捕捉id为123456789的那条数据,将它的内容整体的变成了{money,17},其它键的值会被清除

    数据删除:

     AbcDB.find('123456789').delete() //捕捉id为123456789的那条数据,把它删除
     AbcDB.find('123456789').delete('money') //捕捉id为123456789的那条数据,把它的money字段键删除
     AbcDB.all().delete() //捕捉全部数据,把它们全部删除
     AbcDB.all().delete('money') //捕捉全部数据,把它们的'money'字段键删除

    统计:

     AbcDB.where('money',14).count() //统计money等于14的共有多少条数据

码云特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/
MIT License Copyright (c) 2019 龙邦 <x135356@sina.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于微信数据库api打包的,数据库管理。相对方便的创建和管理你的“微信云数据库” 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/X135356/wxDB.git
git@gitee.com:X135356/wxDB.git
X135356
wxDB
wxDB
master

搜索帮助