封装的 sql log http 三大组件 在编辑器上的方法能代码智能提示
- //DB处理器
- var db = this.tabris.create('SQL', {
- name: 'testorm',
- type: 'mysql'
- });
- //http处理器
- var http = this.tabris.create('HTTP', {
- method: 'GET'
- });
- //log处理器
- var log = this.tabris.create('LOG', {
- trace: true
- });
- db.delete('delete from child_district');
- //从district表里面获取所有城市的Code
- var get_district_sql = "select Code from district";
- var district_code_list = db.query(get_district_sql);
- for (var index = 0; index < district_code_list.length; index++) {
- getChildDistrictAndInsertToDb(district_code_list[index].Code);
- }
- //远程获取
- function getChildDistrictAndInsertToDb(parentCode) {
- log.info(parentCode);
- var re = http.getJson({
- url: 'https://fuwu.sf-express.com/service/address/newAddr/getNewSubAddress?parentCode=' + parentCode
- });
- if (!re.subAddressList || !re.subAddressList.length) return;
- for (var index = 0; index < re.subAddressList.length; index++) {
- var child = re.subAddressList[index];
- var insertSql = "insert into child_district (Name,Code,DataChange_LastTime) VALUES('" + child.distCnName + "','" + child.distCode + "',now())";
- var insertResult = db.insert(insertSql) if (insertResult != 1) {
- log.error(child.distCnName + '插入db失败!');
- } else {
- log.info(child.distCnName + '插入db成功!')
- }
- }
- }
来源: https://www.cnblogs.com/yudongdong/p/8169117.html