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、执行。