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 ) );
}
});
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 ) );
}
});