forked from sql-formatter-org/sql-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
171 lines (158 loc) · 4.92 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>SQL formatter</title>
<meta name="description" content="A whitespace formatter for different query languages" />
<meta property="og:title" content="SQL Formatter" />
<meta
property="og:description"
content="A whitespace formatter for different query languages"
/>
<meta property="og:url" content="https://zeroturnaround.github.io/sql-formatter" />
<link rel="shortcut icon" href="https://static.zeroturnaround.com/theme55/images/favicon.ico" />
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet" />
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Roboto Mono', monospace;
}
header {
position: relative;
height: 120px;
padding: 10px 20px;
border-bottom: 2px solid #8dc63f;
box-sizing: border-box;
}
.select-wrapper {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
margin: 0 0 8px 0;
}
a {
text-decoration: none;
}
main {
overflow: hidden;
display: flex;
flex-direction: row;
-webkit-align-items: stretch;
align-items: stretch;
height: calc(100% - 120px);
}
.input,
.output {
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 50%;
height: 100%;
}
.output {
border-left: 2px solid #8dc63f;
}
textarea {
width: 100%;
padding: 20px;
border: 0;
box-sizing: border-box;
font-size: 1.3em;
resize: none;
outline: none;
line-height: 1.3;
font-family: 'Roboto Mono', monospace;
}
</style>
</head>
<body>
<header>
<h1>SQL Formatter</h1>
<div class="buttons">
<a href="https://www.npmjs.com/package/sql-formatter">
<img src="https://img.shields.io/npm/v/sql-formatter.svg" height="18" />
</a>
<iframe
src="https://ghbtns.com/github-btn.html?user=zeroturnaround&repo=sql-formatter&type=star&count=true"
frameborder="0"
scrolling="0"
width="120px"
height="20px"
style="position: relative; top: 1px"
></iframe>
</div>
<div class="select-wrapper">
<label for="lanugage">Format</label>
<select id="language">
<option value="sql">SQL</option>
<!-- dialects -->
<option value="redshift">AWS Redshift</option>
<option value="db2">DB2</option>
<option value="mariadb">MariaDB</option>
<option value="mysql">MySQL</option>
<option value="n1ql">N1QL</option>
<option value="plsql">PL/SQL</option>
<option value="postgresql">PostgreSQL</option>
<option value="spark">Spark</option>
<option value="tsql">Transact-SQL</option>
</select>
|
<label for="uppercase">Uppercase</label>
<input type="checkbox" id="uppercase" name="uppercase" checked />
</div>
</header>
<main>
<section class="input">
<textarea id="input" autofocus="true" wrap="off">
select supplier_name,city from
(select * from suppliers join addresses on suppliers.address_id=addresses.id)
as suppliers
where supplier_id>500
order by supplier_name asc,city desc;
</textarea
>
</section>
<section class="output">
<textarea id="output" readonly="true" wrap="off"></textarea>
</section>
</main>
<!-- Load from local (for development) -->
<script type="text/javascript" src="dist/sql-formatter.js"></script>
<!-- Fallback to reading from npm -->
<script>
window.sqlFormatter ||
document.write(
unescape(
'%3Cscript type="text/javascript" src="https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js"%3E%3C/script%3E'
)
);
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
let language = document.getElementById('language');
let uppercase = document.getElementById('uppercase');
let input = document.getElementById('input');
let output = document.getElementById('output');
function format() {
console.time('formatting');
output.value = sqlFormatter.format(input.value, {
language: language.options[language.selectedIndex].value,
uppercase: uppercase.checked,
});
console.timeEnd('formatting');
}
input.addEventListener('input', format);
language.addEventListener('change', format);
uppercase.addEventListener('change', format);
format();
});
</script>
</body>
</html>