-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
117 lines (110 loc) · 3.58 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/paper.min.css"
/>
<title>libSQL bindgen</title>
<style>
body {
text-align: center;
margin: auto;
}
textarea {
margin: auto;
width: 100%;
min-height: 300px;
padding: 1rem;
}
input {
text-align: center;
margin: auto;
}
pre {
max-width: 100%;
white-space: pre-wrap;
}
</style>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"
integrity="sha512-aVKKRRi/Q/YV+4mjoKBsE4x3H+BkegoM/em46NNlCqNTmUYADjBbeNefNxYV7giUp0VxICtqdrbqU7iVaeZNXA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
</head>
<body>
<br />
<p>
Brought to you by
<a href="http://libsql.org">libSQL</a> Powered by
<a href="http://github.com/psarna/libsql_bindgen">libSQL bindgen</a>
</p>
<pre class="container margin-bottom">
Type in a single Rust function definition below and get it transformed to a SQL statement,
which you can copy-paste right into libSQL to register your brand new user-defined function.
Use String or &str for text, Vec<u8> for blobs, and i32/i64/f32/f64 for numerics.<p>Available crates:
- bytes, byteorder, itertools, itoa, lz4_flex, magic-crypt, rand (without default features, just std_rng) regex, serde, snap, syn
- more coming soon!</p></pre>
<pre class="container">
Steps to set up libSQL shell with WebAssembly user-defined functions support:
1a. Download the shell binary with WebAssembly support from <a href="https://github.com/libsql/libsql/releases/">here</a>
or
1b. Build from <a href="http://github.com/libsql/libsql">source</a>: ./configure --enable-wasm-runtime && make
2. Run: ./libsql</pre
>
<br />
<form name="form" class="container paper" id="form">
<textarea id="src" name="src">
pub fn encrypt(data: String, key: String) -> String {
use magic_crypt::MagicCryptTrait;
let mc = magic_crypt::new_magic_crypt!(key, 256);
mc.encrypt_str_to_base64(data)
}
</textarea
>
<br />
<input type="checkbox" id="blob" name="blob" />
<label for="blob">as a binary blob</label>
<div class="row flex-edges">
<button type="submit">Generate</button>
<button class="js-copy-button" disabled type="button">Copy SQL</button>
</div>
</form>
<br />
<div class="container">
<pre class="js-result" id="resp" style="text-align: left"></pre>
</div>
</body>
<script>
$('#form').submit(function (e) {
e.preventDefault()
$.ajax({
type: 'POST',
url: 'https://libsql-bindgen-backend.fly.dev/generate',
data: {
src: $('#src').val(),
blob: $('#blob').prop('checked') ? 'yes' : 'no',
},
success: function (data) {
const resultComponent = $('.js-result')
$('.js-result').text(data)
const copyButton = $('.js-copy-button')
copyButton.get(0).scrollIntoView({
behavior: 'smooth',
})
copyButton.removeAttr('disabled')
},
})
})
$('.js-copy-button').click(function () {
const sqlCode = $('.js-result').text()
if (sqlCode) {
navigator.clipboard.writeText(sqlCode)
}
})
</script>
</html>