1.3.3 • Published 4 years ago

wx-cloud-db-falsework v1.3.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

# wx-cloud-db-falsework

a falsework for weixin miniProgram cloud database
微信小程序云开发数据库脚手架

# Install

npm install wx-cloud-db-falsework

# Quick Start

import { DB, Model } from 'path/wx-cloud-db-falsework.min'

class Order extends Model {
  constructor(o) {
    let t = super(o)
    return t
  }
}

// collectionName 默认为model名,如Order默认为order
// collectionKey  默认_id
// cloud 小程序端传 wx.cloud, 云函数端传require('wx-server-sdk')
const Odr = Order.init({ env: '环境ID', cloud, [, collectionName = '集合名称', collectionKey = '主键字段名'] })

let row = await Odr.doc('xxxx').get()
let row = await Odr.find('xxxx')
let row = await Odr.where({_id: 'xxxx'}).get()
let row = await Odr.find(`{_id: this._.eq('xxxx')}`)
let row = await Odr.find({_id: Odr._.eq('xxxx')})

if(row instanceof DB.DbError){

	console.log('error', row)

}else if(row instanceof DB.DbRes){

	console.log('execed sql ==> ', row.sql)

	if(row instanceof DB.DbResultJson){

		console.log('DbResultJson ==> ', row)

	}else {

		// row instanceof DB.DbResultArray
		console.log('DbResultArray ==> ', row)

	}

	// update
	let back = await row.update({
		abc: 888
	}) ==> // { updated:Number }

	// remove
	let back = await row.remove() ==> // { removed:Number }
}

Other Demo

await Odr.add({_id: 'xxxx', abc: 123})

await Odr.add(`{_id: 'xxxx'}`)

await Odr.add({ data:{_id: 'xxxx'}, success(res){}, fail(res){}, complete(res){} })

await Odr.update({abc: 456}, {_id: 'xxxx'})

await Odr.where({_id: 'xxxx'}).update({abc: 456})

await Odr.doc('xxxx').update({abc: 456})

await Odr.doc('xxxx').update({ data: {abc: 456}, success(res){}, fail(res){}, complete(res){} })

await Odr.aggregate().match({abc: 456}).end()

await Odr.doc('xxxx').remove()

await Odr.where({_id: 'xxxx'}).remove()

await Odr.remove({_id: 'xxxx'})

await Odr.remove({ where: {_id: 'xxxx'}, success(res){}, fail(res){}, complete(res){} })

await Odr.remove(`{_id: 'xxxx', abc: this._.eq(456)}`)

await Odr.remove({_id: 'xxxx', abc: Odr_.eq(456)})
1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago