forked from sql2builder/sql2builder.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
127 lines (110 loc) · 3.66 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="Laravel,Eloquent,Builder">
<title>SQL to Laravel Builder</title>
<link href="https://cdn.bootcss.com/font-awesome/5.11.2/css/fontawesome.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bulma/0.7.5/css/bulma.min.css" rel="stylesheet">
</head>
<body>
<section class="hero is-primary is-small">
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title">
Convert Your Legacy SQL to Laravel Query Builder </h1>
</div>
</div>
</section>
<div>
<div class="columns is-mobile is-centered">
<div class="column is-two-thirds">
<div class="content-area">
<div class="box box-offset">
<div class="field">
<div class="control">
<textarea class="textarea" name="sql" rows="10" placeholder="Enter Your Sql" id="input"></textarea>
</div>
</div>
<div class="field">
<div class="field-body">
<div class="field">
<div class="control has-text-centered">
<button class="button is-primary" onclick="convert()">
Convert
</button>
</div>
</div>
</div>
</div>
</div>
<div class="box box-offset">
<div class="field">
<div class="control">
<textarea class="textarea" name="sql" rows="10" placeholder="Output" id="output"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="js/sql-parser.js"></script>
<script src="js/builder.js"></script>
<script>
function convert() {
let input = document.getElementById("input").value;
if (input.trim() == '') {
return;
}
if (input.slice(-1) == ';') {
input = input.slice(0, -1);
}
let parsed = null;
try {
parsed = SQLParser.parse(input);
console.log(parsed);
} catch (e) {
document.getElementById("output").value = e.message;
if (e.message.startsWith('Parse error')) {
console.log('Posting request to GitHub API...');
fetch('https://api.github.com/repos/sql2builder/sql2builder.github.io/issues', {
method: 'post',
body: JSON.stringify({
"title": "Convert failed",
"body": input,
"assignees": [
"sql2builder"
],
"labels": [
"bug"
]
}),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'token 7786eb107fe6bf689802882ca51c42ff820856c6',
}
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log('Created Issue success.');
});
}
}
if (parsed !== null) {
let builder = new Builder(parsed);
let output = '';
try {
output = builder.convert();
} catch (e) {
console.log(e);
output = e.message;
}
document.getElementById("output").value = output;
}
}
</script>
</html>