// 云函数入口文件
const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
const app = new TcbRouter({
event
})
// 添加记录的路由
app.router('add', async (ctx, next) => {
//可以直接调用event
ctx.body = await db.collection('goods').add({
data: {
info: event.info,
address: event.address,
desc: event.desc
}
})
.then((res) => {
return res
})
})
// 获取指定商品信息
app.router('get', async (ctx, next) => {
let _id=event._id
ctx.body = await db.collection('goods').where({
_id
}).get()
.then((res) => {
return res
})
})
// 获取所有商品信息
app.router('getall', async (ctx, next) => {
ctx.body = await db.collection('goods').get()
.then((res) => {
return res
})
})
// 更新商品信息
app.router('updata', async (ctx, next) => {
ctx.body = await db.collection('goods').where({
_id:event._id
}).update({
data:{
info:event.info
}
})
.then((res) => {
return res
})
})
// 删除商品信息
app.router('del', async (ctx, next) => {
ctx.body = await db.collection('goods').where({
_id: event._id
}).remove()
.then((res) => {
return res
})
})
return app.serve()
}
小程序云开发后端js
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 开发者可以使用云开发开发微信小程序、小游戏,无需搭建服务器,即可使用云端能力。 云开发为开发者提供完整的云端支持,...
- 云开发包括三个重要的功能:数据库,存储,云函数 数据库 云开发提供了一个 JSON 数据库,顾名思义,数据库中的每...
- 最近以官方的demo为例配置部署wafer,实现了小程序的授权登陆、获取用户信息以及小程序websocket聊天室...
- 云开发控制台 云开发提供了一个控制台用于可视化管理云资源。控制台包含以下几大模块。 概览:查看云资源的总体使用情况...