数据库
首页 > 数据库> > SQL格式化

SQL格式化

作者:互联网

formatSql = () => {
    let sqlValue = $("#sql").val();
    let keyword = "select from where and count group by orderby";
    keyword = '(' + keyword.replace(/([\+\.\*\|\?\-\(\[\^\$])/g, '\\$1').replace(/\s+/g, '|') + ')';//把匹配关键字中的正则符转义
    let patt = new RegExp(keyword, 'gi');
    let str = sqlValue.replace(patt, function ($, $1) {
      var upr = $1;
      return upr.toUpperCase();
    });
    let formatteSqlValue = sqlFormatter.format(str);
    $("#sql").val(formatteSqlValue);
    this.setState({repsql: formatteSqlValue});
  }

标签:格式化,val,keyword,formatteSqlValue,replace,let,SQL,patt
来源: https://www.cnblogs.com/zhizhi0810/p/11075821.html