javascript + sql编写SQL客户端工具tabris


祝大家2018新年快乐, 前不久发现了一个创意的脚本JtSQL(java编写) 开源地址为:https://github.com/noear/JtSQL JtSQL 特点:
*.结合了JS、SQL、模板理念;
*.保持了JS和SQL的语法高亮(利于DBA审核);
*.方便统一管理、部署、运行
*.像存储过程一样,提供当前上下文及变量支持;
*.像SQL客户端工具一样,即时编写即时运行;
*.像定制统计程序一样,提供过程和逻辑控制能力;
*.服务端运行(别误会成客户端运行啊...) 
         

封装的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://pan.baidu.com/s/1dGZuodt9aMVKWyJ1F0byZw