APICloud数据查询

function insertone() {//插入一条数据
var model = api.require('model');
model.config({
appid : 'A6911882660034',//从官网获取,每个运用不一样
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',//从官网获取,每个运用不一样
host : 'https://d.apicloud.com'//这个为固定值
});
model.insert({
class : 'news',//数据库名称
value : {
title : '12345'//title为列名,'12345'为赋值的列值
}
}, function(ret, err) {//回调方法,在里面执行插入数据成功后所执行的代码
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
// alert("666");
};

function deleteone() {//删除一条数据
var model = api.require('model');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
model.deleteById({
class : 'news',
id : '576792f7ae808c1268950053'
}, function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
}

function updateone() {//更新一条数据
var model = api.require('model');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
model.updateById({
class : 'news',
id : '57669336456dbae84b04ab3a',
value : {
title : 'titletest'
}
}, function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
}

function findone() {//找到一条数据
var model = api.require('model');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
model.findById({
class : 'news',
id : '57669336456dbae84b04ab3a'
}, function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
}

function findmyall() {//找到表全部数据
var model = api.require('model');
var query = api.require('query');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
query.createQuery({
}, function(ret, err) {
//coding...
if (ret && ret.qid) {
model.findAll({
class : 'news',
qid : ret.qid
}, function(ret, err) {
//coding...
//alert(JSON.stringify(ret));
for (var i = 0; i < ret.length; i++) {
alert(JSON.stringify(ret[i]));
}
});
}
});
}

function sumnum() {//查询表数据行数
var model = api.require('model');
var query = api.require('query');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
query.createQuery({
}, function(ret, err) {
//coding...
if (ret && ret.qid) {
model.count({
class : "news",
qid : ret.qid
}, function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
}
});

}

function existtable() {//查询表是否存在
var model = api.require('model');
model.config({
appid : 'A6911882660034',
appKey : '02476E15-2471-6B32-341C-FE0196AFCDD0',
host : 'https://d.apicloud.com'
});
model.exist({
class : "news"
}, function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));
} else {
alert(JSON.stringify(err));
}
});
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 学习目标 掌握云 API 云服务对接 mcm 主要内容 1. 创建数据库(Database),创建表 2. 通过 ...
    guhongyan阅读 191评论 0 0
  • 个人入门学习用笔记、不过多作为参考依据。如有错误欢迎斧正 目录 简书好像不支持锚点、复制搜索(反正也是写给我自己看...
    kirito_song阅读 2,609评论 1 37
  • “当群体的全貌在个体的灵魂中映射出来,同时个体的美德也在群体中鲜活起来,健康的社群生活就会建立”——史代纳 一百多...
    韧性十足的牛皮糖阅读 1,094评论 0 2
  • 喜欢过烟草的味道, 喜欢过下雨天, 现在, 我喜欢抹茶了。 对于雨天也不是那么执着。 今天下雨了, 我没有遇见你,...
    米荼阅读 237评论 0 0

友情链接更多精彩内容