weekly icon indicating copy to clipboard operation
weekly copied to clipboard

【工具自荐】一个 js 库,应用于 vscode 插件开发,简化数据持久化操作。

Open daGaiGuanYu opened this issue 2 years ago • 0 comments

地址:https://github.com/ppz-pro/bd.vscode

Collection 实例

创建 user collection:

const Collection = require('@ppzp/bd/collection')
const userCollection = new Collection('user')

新增数据

创建用户:

await userCollection.insertOne({
  name: 'ppz',
  year: 3
})

查找数据

获取用户,返回一个数组:

const users = userCollection.getAll()

查找数据

按 id 获取用户,返回一个用户:

const user = userCollection.findById(userId)

更新数据

更新用户,整体替换,非局部更新:

const user = userCollection.findById(userId)
user.name = 'ccz'
user.year = 2
await userCollection.replaceOne(user)

删除数据

删除用户:

await userCollection.deleteById(userId)

更多具体细节请参考这个 demo

daGaiGuanYu avatar Sep 17 '22 11:09 daGaiGuanYu