在线网页版接口api文档转建表sql脚本语句

 1、先上网页代码,注意:${selectors}为形参

function replaceStr(str) {
    return str.replace(/.*\[\]/, "text")
        .replace(/integer/, "int")
        .replace(/string/, "varchar(255)")
        .replace(/float/, "varchar(20)")
        .replace(/int/, "bigint")
        .replace(/int64/, "bigint")
        .replace(/struct/, "text")
        .replace(/enum/, "varchar(255)")
};
var set = new Set();
var s = "create table ods_gdt_\n(\n";
s += "app_id int null,\n";
s += "account_id varchar(128) null,\n";
var arr = document.querySelectorAll("${selectors}").forEach(function (item, index, arr) {
    set.add(item.parentElement);
});
 
set.forEach(function (item, index, arr) {
    var fieldName = item.querySelector("td:nth-child(1) div span").innerText;
    if (fieldName != "page"
        && fieldName != "page_size"
        && fieldName != "total_number"
        && fieldName != "total_page") {
        s += fieldName + "\t";
        if (fieldName.endsWith("_cost")) {
            s += "varchar(32)\t" + "null" + " "
        } else if (fieldName.endsWith("_count")) {
            s += "bigint\t" + "null" + " "
        } else if (fieldName == "date") {
            s += "date\t" + "null" + " "
        } else if (fieldName.endsWith("_datetime")) {
            s += "bigint\t" + "null" + " "
        } else if (fieldName.endsWith("_time")) {
            s += "bigint\t" + "null" + " "
        } else if (fieldName == "date") {
            s += "date\t" + "null" + " "
        } else if (fieldName.endsWith("_date")) {
            s += "date\t" + "null" + " "
        } else if (fieldName == "hour") {
            s += "int\t" + "null" + " "
        } else if (fieldName.endsWith("_id")) {
            s += "varchar(128)\t" + "null" + " "
 
        } else if (fieldName.endsWith("rate")) {
            s += "varchar(32)\t" + "null" + " "
        } else {
            s += replaceStr(item.querySelector("td:nth-child(2)").innerText) + "\t" + "null" + " "
        }
        s += "comment" + " " + "'" + item.querySelector("td:nth-child(3)").innerText.replace(/'/g, "").replace(/\n/g, " ") + "'," + "\n";
    }
});
s += "gmt_create       datetime default CURRENT_TIMESTAMP null,\n"
s += "gmt_update       datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP"
s += "\n) ROW_FORMAT=DYNAMIC;"
console.log(s);

2、步骤:

2.1 获取页面selectors

 

2.2 替换掉形参。

3、执行。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值