-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.html
474 lines (360 loc) · 15.2 KB
/
example.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TiDB Wasm Markdown Plugin</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/markdown-it.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/markdown-it-container.js"></script>
<script src="wasm_exec.js"></script>
<script src="./index.js"></script>
<script type="text/javascript" src="jquery.console.js"></script>
<style type="text/css" media="screen">
body{
background: #273238;
}
*{margin:0;padding:0;box-sizing: border-box;}
div.term {
font-size: 14px;
margin-top: 1em
}
div.term div.jquery-console-inner {
background: black;
padding: 0.5em;
overflow: auto
}
div.term div.jquery-console-prompt-box {
color: white;
font-family: monospace;
}
div.term div.jquery-console-focus span.jquery-console-cursor {
background: #444;
color: #eee;
font-weight: bold
}
div.term div.jquery-console-message-error {
color: #ef0505;
font-family: sans-serif;
font-weight: bold;
padding: 0.1em;
}
div.term div.jquery-console-message-success {
color: #09f753;
font-family: monospace;
padding: 0.1em;
white-space: pre;
}
div.term span.jquery-console-prompt-label {
font-weight: bold;
}
.loading-wrap {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
min-width: 100vw;
font-family: "Poppins", sans-serif;
background-color: #000000;
}
#container {
-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
ul li {
list-style: none;
}
.navigation{
-webkit-box-flex: 0;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
-webkit-transition: background 250ms;
transition: background 250ms;
background: #2B3A42;
}
.navigation_inner{
width: 100%;
margin: 0 auto;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
position: relative;
padding: 0.6em 1em;
}
.nav_link{
margin-right: 1.5em;
color: #ffffff;
}
.navigation_logo{
color: #ffffff;
font-size: 1.4em;
}
.navigation_icon{
color: #ffffff;
}
.navigation_links{
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
height: 56px;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.interactive{
min-height: 720px;
background: #2B3A42;
width: 100%;
position: relative;
}
.description{
display: inline-block;
width: 100%;
color: #ffffff;
text-align: center;
margin-top:6em;
}
.install{
max-width: 490px;
max-height: 84px;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
z-index: 1;
}
.install-title{
text-align: center;
font-size:1.8em;
font-weight: 400;
color:#fff;
margin-bottom: 1em;
}
.lang-base{
display:inline-block;
background: #2B3A42;
color: #ffffff;
min-width:450px;
line-height: 1.4em;
padding:0.5em;
-webkit-user-select:text;
-moz-user-select:text;
-ms-user-select:text;
user-select:text;
}
textarea{
outline: none;
border:none;
background: #31424a;
color:#ffffff;
}
#TryIt{
background: #273238;
overflow: hidden;
}
.content a{
color:#ffffff !important;
}
.content p{
font-size: 1.2em;
line-height: 1.8em;
}
.content h1{
font-size: 1.8em;
line-height: 2em;
}
#parser{
outline: none;
border: none;
padding: 0.8em 2.6em;
}
.left-textarea{
width: 41%;
float: left;
padding-left: 10px;
padding-top: 10px;
}
.right-content{
float:right;
width:58%;
min-height:370px;
color:#fff;
padding:10px;
border-left:1px solid #999;
}
</style>
</head>
<body>
<div id="container">
<header class="navigation">
<div class="navigation_inner">
<a href="/" class="navigation_logo">TiDB Wasm Markdown Parser</a>
<nav class="navigation_links">
<a href="#TryIt" class="nav_link">Try it</a>
<a href="https://github.com/imiskolee/tidb-wasm-markdown" class="navigation_icon">Github</a>
</nav>
</div>
</header>
<div class="content">
<div class="interactive">
<h2 class="description">TiDB WASM Markdown Plugin</h2>
<div class="install">
<h4 class="install-title">Install</h4>
<div class="lang-base">
<pre>
<span>git clone https://github.com/imiskolee/tidb-wasm-markdown.git</span>
<span>cd tidb-wasm-markdown</span>
<span>python -m SimpleHTTPServer 8000</span>
<span>Open http://localhost:8080/example.html on your browser(which supported WASM).</span>
</pre>
</div>
</div>
</div>
<div id="TryIt">
<div class="left-textarea">
<textarea name="" id="text" placeholder="::: tisql SELECT * FROM USERS;" style="width: 100%; min-height: 360px; padding: 10px;font-size: 1em; line-height: 1.2em;">
# About this project
Here is a (markdown-it)[] plugin for run TiDB WASM Instance on markdown. just insert keyword `::: tisql ` before which SQL you want to run,
then automatic run the SQL on the TiDB WASM instance and append result panel.
# About TiDB Wasm
This is a amazing idea from Pingcap 2019 hackathon, and try it out on [http://tour.tidb.io](http://tour.tidb.io).
# Demo Doc(from http://tour.tidb.io))
This is a demo site to show how you can use [TiDB-Wasm](https://github.com/pingcap/tidb/pull/13069) to run TiDB SQL statements your browser.
TiDB-Wasm is the second-place project from [2019 TiDB Hackathon](https://pingcap.com/blog/insert-into-tidb-hackathon-2019-values-hack-fun-tidb-ecosystem/) by leveraging the magic of [WebAssembly (Wasm)](https://webassembly.org/), [Golang](https://golang.org/), and [TiDB community](https://github.com/pingcap/community). It is primarily designed for our users to experiment with SQL and test out TiDB compatibility with MySQL queries.
# Explore TiDB SQL with TiDB-Wasm
TiDB is compatible with MySQL, you can use MySQL statements directly in most of the cases. For unsupported features, see [Compatibility with MySQL](https://pingcap.com/docs/stable/reference/mysql-compatibility/).
This page walks you through the basic TiDB SQL statements such as DDL, DML and CRUD operations. For a complete list of the TiDB statements, see [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/).
## Show the TiDB version
To show the TiDB version, use the `SELECT tidb_version()` statement:
::: tisql SELECT tidb_version();
## Create a database
To create a database, use the `CREATE DATABASE` statement:
::: tisql CREATE DATABASE IF NOT EXISTS samp_db;
### Show the databases
To show the databases, use the `SHOW DATABASES` statement:
::: tisql SHOW DATABASES;
### Create, and show a table in the samp_db
Before creating a table, use the `USE samp_db` statement:
::: tisql Use samp_db;
### Create a table
- To create a table, use the `CREATE TABLE` statement:
::: tisql CREATE TABLE table_name column_name data_type constraint;
For example:
::: tisql CREATE TABLE person ( number INT(11) PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),birthday DATE);
- Add `IF NOT EXISTS` to prevent an error if the table exists:
::: tisql CREATE TABLE IF NOT EXISTS person (number INT(11) PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),birthday DATE);
- To view the statement that creates the table, use the `SHOW CREATE` statement:
::: tisql SHOW CREATE table person;
### Show the tables
- To show all the tables in a database, use the `SHOW TABLES` statement:
::: tisql SHOW TABLES FROM samp_db;
- To show all the columns in a table, use the `SHOW FULL COLUMNS` statement:
### Create, show, and drop an index
### Create an index
- To create an index for the column whose value is not unique, use the `CREATE INDEX` or `ALTER TABLE` statement:
::: tisql CREATE INDEX person_num ON person (number);
or
::: tisql ALTER TABLE person ADD INDEX person_num (number);
- To create a unique index for the column whose value is unique, use the `CREATE UNIQUE INDEX` or `ALTER TABLE` statement:
::: tisql CREATE UNIQUE INDEX person_num ON person (number);
or
::: tisql ALTER TABLE person ADD UNIQUE person_num (number);
### Show the indexes
To show all the indexes in a table, use the `SHOW INDEX` statement:
::: tisql SHOW INDEX from person;
### Delete an index
To delete an index, use the `DROP INDEX` or `ALTER TABLE` statement:
::: tisql DROP INDEX person_num ON person;
::: tisql ALTER TABLE person DROP INDEX person_num;
## Insert, select, update, and delete data
### Insert data
To insert data into a table, use the `INSERT` statement:
::: tisql INSERT INTO person VALUES(1,"tom","north","20191027"),(2,"bob","west","20181027"),(3,"jay","north","20181025"),(4,"jerry","north","20181023");
### Select data
To view the data in a table, use the `SELECT` statement:
::: tisql SELECT * FROM person;
You can also sort the data in the table and view the result:
::: tisql SELECT * FROM person ORDER BY birthday;
You can group the data in the table and view the result:
::: tisql SELECT count(*), region FROM person GROUP BY region;
### Explain SQL
To view the SQL query execution plan in TiDB and explore its difference from MySQL, use the `EXPLAIN` statement:
::: tisql EXPLAIN SELECT * FROM person order by birthday;
For more information, see [the TiDB `EXPLAIN` output format](https://pingcap.com/docs/stable/reference/performance/understanding-the-query-execution-plan/#explain-output-format)
### Update data
To update the data in a table, use the `UPDATE` statement:
::: tisql UPDATE person SET birthday='20191106' WHERE name='tom';
::: tisql SELECT * FROM person;
### Delete data
To delete the data in a table, use the `DELETE` statement:
::: tisql DELETE FROM person WHERE number=1;
::: tisql SELECT * FROM person;
If you finish working with the sample table and database, feel free to delete the table and the database:
## Delete a table
To delete a table, use the `DROP TABLE` statement:
::: tisql DROP TABLE person;
or
::: tisql DROP TABLE IF EXISTS person;
## Delete a database
To delete a database, use the `DROP DATABASE` statement:
::: tisql DROP DATABASE samp_db;
## Create, authorize, and delete a user
### Create a user
To create a user, use the `CREATE USER` statement. The following example creates a user named `tiuser` with the password `123456`:
::: tisql CREATE USER 'tiuser'@'localhost' IDENTIFIED BY '123456';
### Authorize a user
- To grant `tiuser` the privilege to retrieve the tables in the `samp_db` database:
::: tisql GRANT SELECT ON samp_db.* TO 'tiuser'@'localhost';
- To check the privileges of `tiuser`:
::: tisql SHOW GRANTS for tiuser@localhost;
### Delete a user
To delete `tiuser`:
::: tisql DROP USER 'tiuser'@'localhost';
# What's next?
After testing out TiDB compatibility with MySQL queries, you can now choose one of the following deployment options to deploy a TiDB cluster on-premise or in-cloud.
- [Deploy TiDB using TiDB-Ansible](https://pingcap.com/docs/stable/how-to/deploy/orchestrated/ansible/) Highly recommended for production deployment.
- [Deploy TiDB using Docker](https://pingcap.com/docs/stable/how-to/deploy/orchestrated/docker/)
- Deploy TiDB using Kubernetes via [TiDB Operator](https://github.com/pingcap/tidb-operator) on public cloud or locally:
- [AWS EKS (Elastic Kubernetes Service)](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/aws-eks/)
- [GKE (Google Kubernetes Engine)](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/gcp-gke/)
- [Google Cloud Shell](https://pingcap.com/docs/stable/tidb-in-kubernetes/get-started/deploy-tidb-from-kubernetes-gke/)
Or deploy TiDB locally using:
- [kind](https://pingcap.com/docs/stable/tidb-in-kubernetes/get-started/deploy-tidb-from-kubernetes-kind/)
- [Minikube](https://pingcap.com/docs/stable/tidb-in-kubernetes/get-started/deploy-tidb-from-kubernetes-minikube/)
- [Deploy TiDB using Binary Tarball](https://pingcap.com/docs/stable/how-to/deploy/from-tarball/production-environment/): To deploy TiDB from a binary tarball in production. Guides for [development](https://pingcap.com/docs/stable/how-to/get-started/deploy-tidb-from-binary/) and [testing](https://pingcap.com/docs/stable/how-to/deploy/from-tarball/testing-environment/) environments are also available.
If you have any questions, feel free to contact us via [TiDB Community Slack](https://pingcap.com/tidbslack) or [Email](mailto:[email protected]).
</textarea>
<input type="button" disabled="disabled" id="parser" value="Tidb Loading...">
</div>
<div class="right-content">
<div id="mdContent">Please press `Parser` button to parse markdown to HTML.</div>
</div>
</div>
</div>
</div>
<script>
TiDBWasmMarkdown.loadTiDB("./main.css").then(function(){
$('#parser').val("Parser");
$('#parser').attr("disabled",false);
})
$("#parser").on("click",function(){
var markdown = $("#text").val();
var md = new markdownit();
TiDBWasmMarkdown.render($("#mdContent"),md,markdown);
})
</script>
</body>
</html>