apiCloud中的数据库操作mcm模块中的model对象

1.添加

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });
        model.insert({
            class: 'user',
            value: {
                username : 'test',
                password : '123456'
            }
        }, function(ret, err){
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

2.修改

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });


        model.updateById({
            class: 'user',
            id: '57eb807babca25f4649f1c0f',
            value: {
                username: 'Tom'
            }
        }, function(ret, err){
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

3.删除

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });
        
        model.deleteById({
            class: 'user',
            id: '57eb807babca25f4649f1c0f'
        }, function(ret, err){
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

4.查找

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });

        model.findById({
            class: 'user',
            id: '57eb82c5abca25f4649f1d22'
        }, function(ret, err){
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

5.查找全部

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });

        model.findAll({
            class: "user",
            qid: ''
        }, function( ret, err ) {
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

6.查询是否存在

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });
        
        model.exist({
            class: "user",
            id: "57eb82c5abca25f4649f1d22"
        }, function( ret, err ) {
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });

422101-20160928165432375-744319456.png

7.结合query进行查询

        var model = api.require('model');
        model.config({
            appId:'xxx',
            appKey: 'xxx',
            host: 'https://d.apicloud.com'
        });

        var query = api.require('query');
        var queryId = query.createQuery();
        query.whereNotEqual({  // 查询id不等于57eb82c5abca25f4649f1d22的数据
            qid: queryId,
            column: 'id',
            value: '57eb82c5abca25f4649f1d22'
        });
        
        model.findAll({
            class: "user",
            qid: queryId
        }, function( ret, err ) {
            if( ret ){
                alert( JSON.stringify( ret ) );
            }else{
                alert( JSON.stringify( err ) );
            }
        });



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5917049.html,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值