欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

增删改查,接口范例

程序员文章站 2022-06-12 18:06:23
...
//测试接口-增

helloAction:function*(self){
var time = getNowFullDate();
var list =self.http._post.list;
var body =self.http._post.body;

   var insertId = yield P('test').add({list:list, body: body,time:time});
   if(!insertId){
       return  this.fail('添加成功');
   }else {
       return  this.fail('添加失败');
   }

},
//测试接口-删
deleteAction:function(){
var time = getNowFullDate();
var affectedRows = yield P('test').where({body: [">", 5]}).delete();
if(!affectedRows){
return this.fail('成功');
}else {
return this.fail('失败');
}
},
//测试接口-改
testmodifyAction:function
(){
var time = getNowFullDate();
yield P('test').where({body: id}).decrement("coins", 10);
if(!insertId){
return this.fail('成功');
}else {
return this.fail('失败');
}
},

//测试接口-查  //所有
queryAction:function*(){
    var time = getNowFullDate();
    var data = yield P('test').select();

        return  this.fail(data);
},

 //测试接口-查  //单个数据
queryAction:function*(){
    var time = getNowFullDate();
    var data = yield P('test').where({body: "4546"}).find();

        return  this.fail(data);
},