You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
guoxinyu_project/scr/wechat-weapp-mapdemo-master/wechat-weapp-mapdemo-master.../cloud/useroption/index.js

84 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
//写有关于数据库操作的地方
//获取数据库的连接对象
const db = cloud.database();
//在一个云函数里面有4种数据库操作。所以要先判断是什么操作增删改查
//增
if(event.option=='add'){
return await db.collection('users').add({
//花括号里面是你要添加的对象
data:event.addData
//可添加多条或一条
//event:包含传过来的所有数据的一个对象
});
}
//删
else if(event.option=="deleteuser"){
return await db.collection('users').where({
//将要删除的值赋给name
User_ID:event.delUser_ID
}).remove();
}
else if(event.option=="deleteusers"){
return await db.collection('users').where({
//将要删除的值赋给name
User_College:event.delUser_College,
User_Grade:event.delUser_Grade,
User_Class:event.delUser_Class
}).remove();
}
//查
else if(event.option=="getID"){
return await db.collection('users').where({
User_ID:event.getUser_ID
}).get({
success:function(res){
return res
}
})
}
else if(event.option=="getCollege"){
return await db.collection('users').where({
User_College:event.getUser_College,
User_Grade:event.getUser_Grade,
User_Class:event.getUser_Class
}).get({
success:function(res){
return res
}
})
}
else if(event.option=="getusers"){
return await db.collection('users').where({
}).get({
success:function(res){
return res
}
})
}
//改
else if(event.option=="update"){
return await db.collection('users').where({
User_ID:event.updateUser_ID
}).update({
data:{
User_College:event.updateUser_College
}
})
}
}