You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body>* {
width: 100%;
box-sizing: border-box;
font-size: 1rem;
line-height: 1.5;
}
</style>
</head>
<body>
<textarea style="height: 40vh;"></textarea>
<button>生成ddl</button>
<pre>
</pre>
<script hidden>
let input = document.body.firstElementChild;
let btn = input.nextElementSibling;
let out = btn.nextElementSibling;
btn.addEventListener("click",()=>{
let lines = input.value?.trim().toLowerCase().split("\n");
let ts = lines[0].toLowerCase().trim().split(/\s+/);
let text = "DROP TABLE IF EXISTS `"+ts[1]+"`;\n";
text += "CREATE TABLE `"+ts[1]+"` (\n";
let id = ""
for(let i=1;i<lines.length;i++){
let line = lines[i];
let as = line.split("\t");
if(i==1){
id = as[0]?.trim();
}
text +=`\t\`${as[0]?.trim()}\` \t${as[2]?.trim()}${as[3]?.trim()?('('+as[3]?.trim()+')'):''}\t${as[4]?.trim()=='yes'?'NOT NULL':'NULL'} COMMENT '${as[1]}',\n`
}
text += "\tPRIMARY KEY (`"+id+"`)\n";
text += ")ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='"+ts[0]+"';";
out.textContent=text;
});
</script>
</body>
</html>