sql_insight 0.1.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Cargo.lock +429 -0
- data/Cargo.toml +7 -0
- data/ext/sql_insight/Cargo.toml +18 -0
- data/ext/sql_insight/extconf.rb +6 -0
- data/ext/sql_insight/src/errors.rs +37 -0
- data/ext/sql_insight/src/lib.rs +9 -0
- data/ext/sql_insight/src/ruby_api/crud_tables.rs +147 -0
- data/ext/sql_insight/src/ruby_api/ident.rs +85 -0
- data/ext/sql_insight/src/ruby_api/mod.rs +29 -0
- data/ext/sql_insight/src/ruby_api/pub_funcs.rs +79 -0
- data/ext/sql_insight/src/ruby_api/table_reference.rs +176 -0
- data/ext/sql_insight/src/ruby_api/tables.rs +69 -0
- data/lib/sql_insight/dialect.rb +17 -0
- data/lib/sql_insight/errors.rb +13 -0
- data/lib/sql_insight/version.rb +5 -0
- data/lib/sql_insight.rb +17 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0042e85cbacf9d9be5912be42e3a8c1720d4cd867e671749c701878175c8b4c7
|
4
|
+
data.tar.gz: 5f8b169edd3e3318fad8165df2df143bbb6b0a739d01844cd2e17a48997705fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e97d77d0e92929c188ce5d9f008048d5222031c9eb35eb3e577b233a9453759baf78bb503f472c272100f3f1257c6852188aff40082adf7344f0374c00b8388e
|
7
|
+
data.tar.gz: 5c3b3ef60a83b22b5c2cf3d49e55b0b4afb83ef36670c4fb5cdcfbb69e03fc1a4af54b36bebdf6a0db49ba87227535e61dbce7c1203490b203b713b56655a5a6
|
data/Cargo.lock
ADDED
@@ -0,0 +1,429 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
version = 3
|
4
|
+
|
5
|
+
[[package]]
|
6
|
+
name = "aho-corasick"
|
7
|
+
version = "1.1.2"
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
+
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
10
|
+
dependencies = [
|
11
|
+
"memchr",
|
12
|
+
]
|
13
|
+
|
14
|
+
[[package]]
|
15
|
+
name = "bindgen"
|
16
|
+
version = "0.69.4"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
|
19
|
+
dependencies = [
|
20
|
+
"bitflags",
|
21
|
+
"cexpr",
|
22
|
+
"clang-sys",
|
23
|
+
"itertools",
|
24
|
+
"lazy_static",
|
25
|
+
"lazycell",
|
26
|
+
"proc-macro2",
|
27
|
+
"quote",
|
28
|
+
"regex",
|
29
|
+
"rustc-hash",
|
30
|
+
"shlex",
|
31
|
+
"syn",
|
32
|
+
]
|
33
|
+
|
34
|
+
[[package]]
|
35
|
+
name = "bitflags"
|
36
|
+
version = "2.4.2"
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
38
|
+
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
39
|
+
|
40
|
+
[[package]]
|
41
|
+
name = "cexpr"
|
42
|
+
version = "0.6.0"
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
44
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
45
|
+
dependencies = [
|
46
|
+
"nom",
|
47
|
+
]
|
48
|
+
|
49
|
+
[[package]]
|
50
|
+
name = "cfg-if"
|
51
|
+
version = "1.0.0"
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
53
|
+
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
54
|
+
|
55
|
+
[[package]]
|
56
|
+
name = "clang-sys"
|
57
|
+
version = "1.7.0"
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
59
|
+
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
|
60
|
+
dependencies = [
|
61
|
+
"glob",
|
62
|
+
"libc",
|
63
|
+
"libloading",
|
64
|
+
]
|
65
|
+
|
66
|
+
[[package]]
|
67
|
+
name = "either"
|
68
|
+
version = "1.10.0"
|
69
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
70
|
+
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
71
|
+
|
72
|
+
[[package]]
|
73
|
+
name = "glob"
|
74
|
+
version = "0.3.1"
|
75
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
76
|
+
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
77
|
+
|
78
|
+
[[package]]
|
79
|
+
name = "itertools"
|
80
|
+
version = "0.12.1"
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
82
|
+
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
83
|
+
dependencies = [
|
84
|
+
"either",
|
85
|
+
]
|
86
|
+
|
87
|
+
[[package]]
|
88
|
+
name = "lazy_static"
|
89
|
+
version = "1.4.0"
|
90
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
91
|
+
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
92
|
+
|
93
|
+
[[package]]
|
94
|
+
name = "lazycell"
|
95
|
+
version = "1.3.0"
|
96
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
97
|
+
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
98
|
+
|
99
|
+
[[package]]
|
100
|
+
name = "libc"
|
101
|
+
version = "0.2.153"
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
103
|
+
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
104
|
+
|
105
|
+
[[package]]
|
106
|
+
name = "libloading"
|
107
|
+
version = "0.8.1"
|
108
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
109
|
+
checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161"
|
110
|
+
dependencies = [
|
111
|
+
"cfg-if",
|
112
|
+
"windows-sys",
|
113
|
+
]
|
114
|
+
|
115
|
+
[[package]]
|
116
|
+
name = "log"
|
117
|
+
version = "0.4.20"
|
118
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
119
|
+
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
120
|
+
|
121
|
+
[[package]]
|
122
|
+
name = "magnus"
|
123
|
+
version = "0.6.2"
|
124
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
125
|
+
checksum = "4778544796676e8428e9c622460ebf284bea52d8b10db3aeb449d8b5e61b3a13"
|
126
|
+
dependencies = [
|
127
|
+
"magnus-macros",
|
128
|
+
"rb-sys",
|
129
|
+
"rb-sys-env",
|
130
|
+
"seq-macro",
|
131
|
+
]
|
132
|
+
|
133
|
+
[[package]]
|
134
|
+
name = "magnus-macros"
|
135
|
+
version = "0.6.0"
|
136
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
137
|
+
checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
|
138
|
+
dependencies = [
|
139
|
+
"proc-macro2",
|
140
|
+
"quote",
|
141
|
+
"syn",
|
142
|
+
]
|
143
|
+
|
144
|
+
[[package]]
|
145
|
+
name = "memchr"
|
146
|
+
version = "2.7.1"
|
147
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
148
|
+
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
149
|
+
|
150
|
+
[[package]]
|
151
|
+
name = "minimal-lexical"
|
152
|
+
version = "0.2.1"
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
154
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
155
|
+
|
156
|
+
[[package]]
|
157
|
+
name = "nom"
|
158
|
+
version = "7.1.3"
|
159
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
160
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
161
|
+
dependencies = [
|
162
|
+
"memchr",
|
163
|
+
"minimal-lexical",
|
164
|
+
]
|
165
|
+
|
166
|
+
[[package]]
|
167
|
+
name = "proc-macro2"
|
168
|
+
version = "1.0.78"
|
169
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
170
|
+
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
171
|
+
dependencies = [
|
172
|
+
"unicode-ident",
|
173
|
+
]
|
174
|
+
|
175
|
+
[[package]]
|
176
|
+
name = "quote"
|
177
|
+
version = "1.0.35"
|
178
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
179
|
+
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
180
|
+
dependencies = [
|
181
|
+
"proc-macro2",
|
182
|
+
]
|
183
|
+
|
184
|
+
[[package]]
|
185
|
+
name = "rb-sys"
|
186
|
+
version = "0.9.88"
|
187
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
188
|
+
checksum = "d11b0965e6df9ef800ac71efc46070960a119f92af1b64d6acd4c357dc139350"
|
189
|
+
dependencies = [
|
190
|
+
"rb-sys-build",
|
191
|
+
]
|
192
|
+
|
193
|
+
[[package]]
|
194
|
+
name = "rb-sys-build"
|
195
|
+
version = "0.9.88"
|
196
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
197
|
+
checksum = "5c0fce6e53552df8fcd3e4269d7944b0afa38db70d252bbf12caad454caf6d83"
|
198
|
+
dependencies = [
|
199
|
+
"bindgen",
|
200
|
+
"lazy_static",
|
201
|
+
"proc-macro2",
|
202
|
+
"quote",
|
203
|
+
"regex",
|
204
|
+
"shell-words",
|
205
|
+
"syn",
|
206
|
+
]
|
207
|
+
|
208
|
+
[[package]]
|
209
|
+
name = "rb-sys-env"
|
210
|
+
version = "0.1.2"
|
211
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
212
|
+
checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
213
|
+
|
214
|
+
[[package]]
|
215
|
+
name = "rb-sys-test-helpers"
|
216
|
+
version = "0.2.0"
|
217
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
218
|
+
checksum = "bbd592029353df7955a76ca0b1bf0d9ccc57feab96615f80d1fe756462864949"
|
219
|
+
dependencies = [
|
220
|
+
"rb-sys",
|
221
|
+
"rb-sys-env",
|
222
|
+
"rb-sys-test-helpers-macros",
|
223
|
+
]
|
224
|
+
|
225
|
+
[[package]]
|
226
|
+
name = "rb-sys-test-helpers-macros"
|
227
|
+
version = "0.2.0"
|
228
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
229
|
+
checksum = "c21f156459adb755d58f73dbd783dc1de8b403635e637f7d1daec1c7a920c1f5"
|
230
|
+
dependencies = [
|
231
|
+
"quote",
|
232
|
+
"syn",
|
233
|
+
]
|
234
|
+
|
235
|
+
[[package]]
|
236
|
+
name = "regex"
|
237
|
+
version = "1.10.3"
|
238
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
239
|
+
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
|
240
|
+
dependencies = [
|
241
|
+
"aho-corasick",
|
242
|
+
"memchr",
|
243
|
+
"regex-automata",
|
244
|
+
"regex-syntax",
|
245
|
+
]
|
246
|
+
|
247
|
+
[[package]]
|
248
|
+
name = "regex-automata"
|
249
|
+
version = "0.4.5"
|
250
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
251
|
+
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
|
252
|
+
dependencies = [
|
253
|
+
"aho-corasick",
|
254
|
+
"memchr",
|
255
|
+
"regex-syntax",
|
256
|
+
]
|
257
|
+
|
258
|
+
[[package]]
|
259
|
+
name = "regex-syntax"
|
260
|
+
version = "0.8.2"
|
261
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
262
|
+
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
263
|
+
|
264
|
+
[[package]]
|
265
|
+
name = "rustc-hash"
|
266
|
+
version = "1.1.0"
|
267
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
268
|
+
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
269
|
+
|
270
|
+
[[package]]
|
271
|
+
name = "seq-macro"
|
272
|
+
version = "0.3.5"
|
273
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
274
|
+
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
275
|
+
|
276
|
+
[[package]]
|
277
|
+
name = "shell-words"
|
278
|
+
version = "1.1.0"
|
279
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
280
|
+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
281
|
+
|
282
|
+
[[package]]
|
283
|
+
name = "shlex"
|
284
|
+
version = "1.3.0"
|
285
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
286
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
287
|
+
|
288
|
+
[[package]]
|
289
|
+
name = "sql-insight"
|
290
|
+
version = "0.1.1"
|
291
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
292
|
+
checksum = "08f0f793b0e0bff0d2745502e14f8676c62215f42d8c1a82ea2f402d4ad3fb63"
|
293
|
+
dependencies = [
|
294
|
+
"sqlparser",
|
295
|
+
"thiserror",
|
296
|
+
]
|
297
|
+
|
298
|
+
[[package]]
|
299
|
+
name = "sql_insight"
|
300
|
+
version = "0.1.0"
|
301
|
+
dependencies = [
|
302
|
+
"magnus",
|
303
|
+
"rb-sys-test-helpers",
|
304
|
+
"sql-insight",
|
305
|
+
]
|
306
|
+
|
307
|
+
[[package]]
|
308
|
+
name = "sqlparser"
|
309
|
+
version = "0.43.1"
|
310
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
311
|
+
checksum = "f95c4bae5aba7cd30bd506f7140026ade63cff5afd778af8854026f9606bf5d4"
|
312
|
+
dependencies = [
|
313
|
+
"log",
|
314
|
+
"sqlparser_derive",
|
315
|
+
]
|
316
|
+
|
317
|
+
[[package]]
|
318
|
+
name = "sqlparser_derive"
|
319
|
+
version = "0.2.2"
|
320
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
321
|
+
checksum = "01b2e185515564f15375f593fb966b5718bc624ba77fe49fa4616ad619690554"
|
322
|
+
dependencies = [
|
323
|
+
"proc-macro2",
|
324
|
+
"quote",
|
325
|
+
"syn",
|
326
|
+
]
|
327
|
+
|
328
|
+
[[package]]
|
329
|
+
name = "syn"
|
330
|
+
version = "2.0.48"
|
331
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
332
|
+
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
333
|
+
dependencies = [
|
334
|
+
"proc-macro2",
|
335
|
+
"quote",
|
336
|
+
"unicode-ident",
|
337
|
+
]
|
338
|
+
|
339
|
+
[[package]]
|
340
|
+
name = "thiserror"
|
341
|
+
version = "1.0.57"
|
342
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
343
|
+
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
|
344
|
+
dependencies = [
|
345
|
+
"thiserror-impl",
|
346
|
+
]
|
347
|
+
|
348
|
+
[[package]]
|
349
|
+
name = "thiserror-impl"
|
350
|
+
version = "1.0.57"
|
351
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
352
|
+
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
|
353
|
+
dependencies = [
|
354
|
+
"proc-macro2",
|
355
|
+
"quote",
|
356
|
+
"syn",
|
357
|
+
]
|
358
|
+
|
359
|
+
[[package]]
|
360
|
+
name = "unicode-ident"
|
361
|
+
version = "1.0.12"
|
362
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
363
|
+
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
364
|
+
|
365
|
+
[[package]]
|
366
|
+
name = "windows-sys"
|
367
|
+
version = "0.48.0"
|
368
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
369
|
+
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
370
|
+
dependencies = [
|
371
|
+
"windows-targets",
|
372
|
+
]
|
373
|
+
|
374
|
+
[[package]]
|
375
|
+
name = "windows-targets"
|
376
|
+
version = "0.48.5"
|
377
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
378
|
+
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
379
|
+
dependencies = [
|
380
|
+
"windows_aarch64_gnullvm",
|
381
|
+
"windows_aarch64_msvc",
|
382
|
+
"windows_i686_gnu",
|
383
|
+
"windows_i686_msvc",
|
384
|
+
"windows_x86_64_gnu",
|
385
|
+
"windows_x86_64_gnullvm",
|
386
|
+
"windows_x86_64_msvc",
|
387
|
+
]
|
388
|
+
|
389
|
+
[[package]]
|
390
|
+
name = "windows_aarch64_gnullvm"
|
391
|
+
version = "0.48.5"
|
392
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
393
|
+
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
394
|
+
|
395
|
+
[[package]]
|
396
|
+
name = "windows_aarch64_msvc"
|
397
|
+
version = "0.48.5"
|
398
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
399
|
+
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
400
|
+
|
401
|
+
[[package]]
|
402
|
+
name = "windows_i686_gnu"
|
403
|
+
version = "0.48.5"
|
404
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
405
|
+
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
406
|
+
|
407
|
+
[[package]]
|
408
|
+
name = "windows_i686_msvc"
|
409
|
+
version = "0.48.5"
|
410
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
411
|
+
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
412
|
+
|
413
|
+
[[package]]
|
414
|
+
name = "windows_x86_64_gnu"
|
415
|
+
version = "0.48.5"
|
416
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
417
|
+
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
418
|
+
|
419
|
+
[[package]]
|
420
|
+
name = "windows_x86_64_gnullvm"
|
421
|
+
version = "0.48.5"
|
422
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
423
|
+
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
424
|
+
|
425
|
+
[[package]]
|
426
|
+
name = "windows_x86_64_msvc"
|
427
|
+
version = "0.48.5"
|
428
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
429
|
+
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
data/Cargo.toml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
[package]
|
2
|
+
name = "sql_insight"
|
3
|
+
version = "0.1.0"
|
4
|
+
edition = "2021"
|
5
|
+
authors = ["Takahiro Ebato <takahiro.ebato@gmail.com>"]
|
6
|
+
license = "MIT"
|
7
|
+
publish = false
|
8
|
+
|
9
|
+
[lib]
|
10
|
+
crate-type = ["cdylib"]
|
11
|
+
|
12
|
+
[dependencies]
|
13
|
+
magnus = { version = "0.6.2" }
|
14
|
+
sql-insight = { version = "0.1.1" }
|
15
|
+
|
16
|
+
[dev-dependencies]
|
17
|
+
magnus = { version = "0.6.2", features = ["embed"] }
|
18
|
+
rb-sys-test-helpers = { version = "0.2" }
|
@@ -0,0 +1,37 @@
|
|
1
|
+
use crate::ruby_api::root;
|
2
|
+
use magnus::{
|
3
|
+
exception::ExceptionClass, prelude::*, value::Lazy, Error, Ruby,
|
4
|
+
};
|
5
|
+
|
6
|
+
// define class `SqlInsight::Error < StandardError`
|
7
|
+
pub static ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
|
8
|
+
root()
|
9
|
+
.define_error("Error", ruby.exception_standard_error())
|
10
|
+
.unwrap()
|
11
|
+
});
|
12
|
+
|
13
|
+
// define class `SqlInsight::ParserError < SqlInsight::Error`
|
14
|
+
pub static PARSER_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
|
15
|
+
root()
|
16
|
+
.define_error("ParserError", ruby.get_inner(&ERROR))
|
17
|
+
.unwrap()
|
18
|
+
});
|
19
|
+
|
20
|
+
// define class `SqlInsight::AnalysisError < SqlInsight::Error`
|
21
|
+
pub static ANALYSIS_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
|
22
|
+
root()
|
23
|
+
.define_error("AnalysisError", ruby.get_inner(&ERROR))
|
24
|
+
.unwrap()
|
25
|
+
});
|
26
|
+
|
27
|
+
pub fn convert_to_rb_error(ruby: &Ruby, error: sql_insight::error::Error) -> Error {
|
28
|
+
match error {
|
29
|
+
sql_insight::error::Error::ParserError(error) => {
|
30
|
+
Error::new(ruby.get_inner(&PARSER_ERROR), error.to_string())
|
31
|
+
}
|
32
|
+
sql_insight::error::Error::AnalysisError(error) => {
|
33
|
+
Error::new(ruby.get_inner(&ANALYSIS_ERROR), error.to_string())
|
34
|
+
}
|
35
|
+
_ => Error::new(ruby.get_inner(&ERROR), error.to_string()),
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
use crate::ruby_api::{root, RbTableReference};
|
2
|
+
use magnus::{class, function, method, Error, IntoValueFromNative, Module, Object, RArray};
|
3
|
+
use sql_insight::CrudTables;
|
4
|
+
use std::cell::RefCell;
|
5
|
+
|
6
|
+
#[derive(Default, Clone)]
|
7
|
+
struct RbCrudTablesInner {
|
8
|
+
create_tables: Vec<RbTableReference>,
|
9
|
+
read_tables: Vec<RbTableReference>,
|
10
|
+
update_tables: Vec<RbTableReference>,
|
11
|
+
delete_tables: Vec<RbTableReference>,
|
12
|
+
}
|
13
|
+
|
14
|
+
impl RbCrudTablesInner {
|
15
|
+
pub fn new(
|
16
|
+
create_tables: RArray,
|
17
|
+
read_tables: RArray,
|
18
|
+
update_tables: RArray,
|
19
|
+
delete_tables: RArray,
|
20
|
+
) -> Result<Self, Error> {
|
21
|
+
Ok(Self {
|
22
|
+
create_tables: create_tables.to_vec::<RbTableReference>()?,
|
23
|
+
read_tables: read_tables.to_vec::<RbTableReference>()?,
|
24
|
+
update_tables: update_tables.to_vec::<RbTableReference>()?,
|
25
|
+
delete_tables: delete_tables.to_vec::<RbTableReference>()?,
|
26
|
+
})
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
#[magnus::wrap(class = "SqlInsight::CrudTables")]
|
31
|
+
pub struct RbCrudTables {
|
32
|
+
inner: RefCell<RbCrudTablesInner>,
|
33
|
+
}
|
34
|
+
|
35
|
+
unsafe impl IntoValueFromNative for RbCrudTables {}
|
36
|
+
|
37
|
+
impl Default for RbCrudTables {
|
38
|
+
fn default() -> Self {
|
39
|
+
Self {
|
40
|
+
inner: RefCell::new(RbCrudTablesInner::default()),
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
impl RbCrudTables {
|
46
|
+
pub fn new(
|
47
|
+
create_tables: RArray,
|
48
|
+
read_tables: RArray,
|
49
|
+
update_tables: RArray,
|
50
|
+
delete_tables: RArray,
|
51
|
+
) -> Result<Self, Error> {
|
52
|
+
Ok(Self {
|
53
|
+
inner: RefCell::new(RbCrudTablesInner::new(
|
54
|
+
create_tables,
|
55
|
+
read_tables,
|
56
|
+
update_tables,
|
57
|
+
delete_tables,
|
58
|
+
)?),
|
59
|
+
})
|
60
|
+
}
|
61
|
+
|
62
|
+
pub fn from_crud_tables(crud_tables: &CrudTables) -> RbCrudTables {
|
63
|
+
RbCrudTables {
|
64
|
+
inner: RefCell::new(RbCrudTablesInner {
|
65
|
+
create_tables: crud_tables
|
66
|
+
.create_tables
|
67
|
+
.iter()
|
68
|
+
.map(RbTableReference::from_table_reference)
|
69
|
+
.collect(),
|
70
|
+
read_tables: crud_tables
|
71
|
+
.read_tables
|
72
|
+
.iter()
|
73
|
+
.map(RbTableReference::from_table_reference)
|
74
|
+
.collect(),
|
75
|
+
update_tables: crud_tables
|
76
|
+
.update_tables
|
77
|
+
.iter()
|
78
|
+
.map(RbTableReference::from_table_reference)
|
79
|
+
.collect(),
|
80
|
+
delete_tables: crud_tables
|
81
|
+
.delete_tables
|
82
|
+
.iter()
|
83
|
+
.map(RbTableReference::from_table_reference)
|
84
|
+
.collect(),
|
85
|
+
}),
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
fn create_tables(&self) -> RArray {
|
90
|
+
RArray::from_vec(self.inner.borrow().create_tables.clone())
|
91
|
+
}
|
92
|
+
|
93
|
+
fn set_create_tables(&self, create_tables: RArray) -> Result<(), Error> {
|
94
|
+
self.inner.borrow_mut().create_tables = create_tables.to_vec::<RbTableReference>()?;
|
95
|
+
Ok(())
|
96
|
+
}
|
97
|
+
|
98
|
+
fn read_tables(&self) -> RArray {
|
99
|
+
RArray::from_vec(self.inner.borrow().read_tables.clone())
|
100
|
+
}
|
101
|
+
|
102
|
+
fn set_read_tables(&self, read_tables: RArray) -> Result<(), Error> {
|
103
|
+
self.inner.borrow_mut().read_tables = read_tables.to_vec::<RbTableReference>()?;
|
104
|
+
Ok(())
|
105
|
+
}
|
106
|
+
|
107
|
+
fn update_tables(&self) -> RArray {
|
108
|
+
RArray::from_vec(self.inner.borrow().update_tables.clone())
|
109
|
+
}
|
110
|
+
|
111
|
+
fn set_update_tables(&self, update_tables: RArray) -> Result<(), Error> {
|
112
|
+
self.inner.borrow_mut().update_tables = update_tables.to_vec::<RbTableReference>()?;
|
113
|
+
Ok(())
|
114
|
+
}
|
115
|
+
|
116
|
+
fn delete_tables(&self) -> RArray {
|
117
|
+
RArray::from_vec(self.inner.borrow().delete_tables.clone())
|
118
|
+
}
|
119
|
+
|
120
|
+
fn set_delete_tables(&self, delete_tables: RArray) -> Result<(), Error> {
|
121
|
+
self.inner.borrow_mut().delete_tables = delete_tables.to_vec::<RbTableReference>()?;
|
122
|
+
Ok(())
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
pub fn init() -> Result<(), Error> {
|
127
|
+
let class = root().define_class("CrudTables", class::object())?;
|
128
|
+
class.define_singleton_method("new", function!(RbCrudTables::new, 4))?;
|
129
|
+
class.define_method("create_tables", method!(RbCrudTables::create_tables, 0))?;
|
130
|
+
class.define_method(
|
131
|
+
"create_tables=",
|
132
|
+
method!(RbCrudTables::set_create_tables, 1),
|
133
|
+
)?;
|
134
|
+
class.define_method("read_tables", method!(RbCrudTables::read_tables, 0))?;
|
135
|
+
class.define_method("read_tables=", method!(RbCrudTables::set_read_tables, 1))?;
|
136
|
+
class.define_method("update_tables", method!(RbCrudTables::update_tables, 0))?;
|
137
|
+
class.define_method(
|
138
|
+
"update_tables=",
|
139
|
+
method!(RbCrudTables::set_update_tables, 1),
|
140
|
+
)?;
|
141
|
+
class.define_method("delete_tables", method!(RbCrudTables::delete_tables, 0))?;
|
142
|
+
class.define_method(
|
143
|
+
"delete_tables=",
|
144
|
+
method!(RbCrudTables::set_delete_tables, 1),
|
145
|
+
)?;
|
146
|
+
Ok(())
|
147
|
+
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
use crate::ruby_api::root;
|
2
|
+
use core::fmt;
|
3
|
+
use magnus::value::ReprValue;
|
4
|
+
use magnus::{class, function, method, Error, Module, Object, TryConvert};
|
5
|
+
use sql_insight::sqlparser::ast::Ident;
|
6
|
+
use std::cell::RefCell;
|
7
|
+
|
8
|
+
#[derive(Clone)]
|
9
|
+
#[magnus::wrap(class = "SqlInsight::Ident")]
|
10
|
+
pub struct RbIdent {
|
11
|
+
pub inner: RefCell<Ident>,
|
12
|
+
}
|
13
|
+
|
14
|
+
impl TryConvert for RbIdent {
|
15
|
+
fn try_convert(val: magnus::Value) -> Result<Self, Error> {
|
16
|
+
Ok(Self {
|
17
|
+
inner: RefCell::new(Ident {
|
18
|
+
value: val.funcall("value", ())?,
|
19
|
+
quote_style: val.funcall("quote_style", ())?,
|
20
|
+
}),
|
21
|
+
})
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
impl Default for RbIdent {
|
26
|
+
fn default() -> Self {
|
27
|
+
Self {
|
28
|
+
inner: RefCell::new(Ident::new(String::new())),
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
impl fmt::Display for RbIdent {
|
34
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
35
|
+
write!(f, "{}", self.inner.borrow())
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
impl RbIdent {
|
40
|
+
pub fn new(value: String, quote: Option<char>) -> Self {
|
41
|
+
Self {
|
42
|
+
inner: RefCell::new(Ident {
|
43
|
+
value,
|
44
|
+
quote_style: quote,
|
45
|
+
}),
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
pub fn from_ident(ident: &Ident) -> Self {
|
50
|
+
Self {
|
51
|
+
inner: RefCell::new(ident.clone()),
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
fn value(&self) -> String {
|
56
|
+
self.inner.borrow().value.clone()
|
57
|
+
}
|
58
|
+
|
59
|
+
fn set_value(&self, value: String) {
|
60
|
+
self.inner.borrow_mut().value = value;
|
61
|
+
}
|
62
|
+
|
63
|
+
fn quote_style(&self) -> Option<char> {
|
64
|
+
self.inner.borrow().quote_style
|
65
|
+
}
|
66
|
+
|
67
|
+
fn set_quote_style(&self, quote_style: Option<char>) {
|
68
|
+
self.inner.borrow_mut().quote_style = quote_style;
|
69
|
+
}
|
70
|
+
|
71
|
+
fn to_s(&self) -> String {
|
72
|
+
self.inner.borrow().to_string()
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
pub fn init() -> Result<(), Error> {
|
77
|
+
let class = root().define_class("Ident", class::object())?;
|
78
|
+
class.define_singleton_method("new", function!(RbIdent::new, 2))?;
|
79
|
+
class.define_method("value", method!(RbIdent::value, 0))?;
|
80
|
+
class.define_method("value=", method!(RbIdent::set_value, 1))?;
|
81
|
+
class.define_method("quote_style", method!(RbIdent::quote_style, 0))?;
|
82
|
+
class.define_method("quote_style=", method!(RbIdent::set_quote_style, 1))?;
|
83
|
+
class.define_method("to_s", method!(RbIdent::to_s, 0))?;
|
84
|
+
Ok(())
|
85
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
use magnus::value::Lazy;
|
2
|
+
use magnus::{Error, RModule, Ruby};
|
3
|
+
|
4
|
+
mod crud_tables;
|
5
|
+
mod ident;
|
6
|
+
mod pub_funcs;
|
7
|
+
mod table_reference;
|
8
|
+
mod tables;
|
9
|
+
|
10
|
+
pub use crud_tables::RbCrudTables;
|
11
|
+
|
12
|
+
pub use table_reference::RbTableReference;
|
13
|
+
pub use tables::RbTables;
|
14
|
+
|
15
|
+
pub fn root() -> RModule {
|
16
|
+
static ROOT: Lazy<RModule> = Lazy::new(|ruby| ruby.define_module("SqlInsight").unwrap());
|
17
|
+
let ruby = Ruby::get().unwrap();
|
18
|
+
ruby.get_inner(&ROOT)
|
19
|
+
}
|
20
|
+
|
21
|
+
pub fn init() -> Result<(), Error> {
|
22
|
+
ident::init()?;
|
23
|
+
table_reference::init()?;
|
24
|
+
tables::init()?;
|
25
|
+
crud_tables::init()?;
|
26
|
+
pub_funcs::init()?;
|
27
|
+
|
28
|
+
Ok(())
|
29
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
use crate::errors::{convert_to_rb_error};
|
2
|
+
use crate::ruby_api::root;
|
3
|
+
use crate::ruby_api::{RbCrudTables, RbTables};
|
4
|
+
use magnus::{exception, function, Error, Object, RArray, Ruby};
|
5
|
+
use sql_insight::sqlparser::dialect;
|
6
|
+
use sql_insight::sqlparser::dialect::Dialect;
|
7
|
+
use sql_insight::NormalizerOptions;
|
8
|
+
|
9
|
+
fn get_dialect(dialect_name: &str) -> Result<Box<dyn Dialect>, Error> {
|
10
|
+
dialect::dialect_from_str(dialect_name).ok_or_else(|| {
|
11
|
+
Error::new(
|
12
|
+
exception::arg_error(),
|
13
|
+
format!("Unknown dialect: {}", dialect_name),
|
14
|
+
)
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
pub fn rb_format(ruby: &Ruby, dialect_name: String, sql: String) -> Result<Vec<String>, Error> {
|
19
|
+
match sql_insight::format(get_dialect(dialect_name.as_str())?.as_ref(), sql.as_str()) {
|
20
|
+
Ok(result) => Ok(result),
|
21
|
+
Err(error) => Err(convert_to_rb_error(ruby, error)),
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
fn rb_normalize(ruby: &Ruby, dialect_name: String, sql: String) -> Result<Vec<String>, Error> {
|
26
|
+
match sql_insight::normalize_with_options(
|
27
|
+
get_dialect(dialect_name.as_str())?.as_ref(),
|
28
|
+
sql.as_str(),
|
29
|
+
NormalizerOptions::new(),
|
30
|
+
) {
|
31
|
+
Ok(result) => Ok(result),
|
32
|
+
Err(error) => Err(convert_to_rb_error(ruby, error)),
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
fn rb_extract_tables(ruby: &Ruby, dialect_name: String, sql: String) -> Result<RArray, Error> {
|
37
|
+
match sql_insight::extract_tables(get_dialect(dialect_name.as_str())?.as_ref(), sql.as_str()) {
|
38
|
+
Ok(result) => {
|
39
|
+
let mut results_of_tables = vec![];
|
40
|
+
for tables in result {
|
41
|
+
match tables {
|
42
|
+
Ok(tables) => results_of_tables.push(RbTables::from_tables(&tables)),
|
43
|
+
Err(error) => return Err(convert_to_rb_error(ruby, error)),
|
44
|
+
}
|
45
|
+
}
|
46
|
+
Ok(RArray::from_vec(results_of_tables))
|
47
|
+
}
|
48
|
+
Err(error) => Err(convert_to_rb_error(ruby, error)),
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
fn rb_extract_crud_tables(ruby: &Ruby, dialect_name: String, sql: String) -> Result<RArray, Error> {
|
53
|
+
match sql_insight::extract_crud_tables(
|
54
|
+
get_dialect(dialect_name.as_str())?.as_ref(),
|
55
|
+
sql.as_str(),
|
56
|
+
) {
|
57
|
+
Ok(result) => {
|
58
|
+
let mut results_of_crud_tables = vec![];
|
59
|
+
for crud_tables in result {
|
60
|
+
match crud_tables {
|
61
|
+
Ok(crud_tables) => {
|
62
|
+
results_of_crud_tables.push(RbCrudTables::from_crud_tables(&crud_tables))
|
63
|
+
}
|
64
|
+
Err(error) => return Err(convert_to_rb_error(ruby, error)),
|
65
|
+
}
|
66
|
+
}
|
67
|
+
Ok(RArray::from_vec(results_of_crud_tables))
|
68
|
+
}
|
69
|
+
Err(error) => Err(convert_to_rb_error(ruby, error)),
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
pub fn init() -> Result<(), Error> {
|
74
|
+
root().define_singleton_method("format", function!(rb_format, 2))?;
|
75
|
+
root().define_singleton_method("normalize", function!(rb_normalize, 2))?;
|
76
|
+
root().define_singleton_method("extract_tables", function!(rb_extract_tables, 2))?;
|
77
|
+
root().define_singleton_method("extract_crud_tables", function!(rb_extract_crud_tables, 2))?;
|
78
|
+
Ok(())
|
79
|
+
}
|
@@ -0,0 +1,176 @@
|
|
1
|
+
use crate::ruby_api::ident::RbIdent;
|
2
|
+
|
3
|
+
use core::fmt;
|
4
|
+
use std::cell::RefCell;
|
5
|
+
|
6
|
+
use crate::ruby_api::root;
|
7
|
+
use magnus::try_convert::TryConvertOwned;
|
8
|
+
use magnus::value::ReprValue;
|
9
|
+
use magnus::{
|
10
|
+
class, function, method, Error, IntoValueFromNative, Module, Object, RClass, TryConvert, Value,
|
11
|
+
};
|
12
|
+
use sql_insight::TableReference;
|
13
|
+
|
14
|
+
#[derive(Default, Clone)]
|
15
|
+
pub struct RbTableReferenceInner {
|
16
|
+
catalog: Option<RbIdent>,
|
17
|
+
schema: Option<RbIdent>,
|
18
|
+
name: RbIdent,
|
19
|
+
alias: Option<RbIdent>,
|
20
|
+
}
|
21
|
+
|
22
|
+
impl TryConvert for RbTableReferenceInner {
|
23
|
+
fn try_convert(val: Value) -> Result<Self, Error> {
|
24
|
+
if val.is_kind_of(root().const_get::<_, RClass>("TableReference")?) {
|
25
|
+
Ok(Self {
|
26
|
+
catalog: val.funcall("catalog", ())?,
|
27
|
+
schema: val.funcall("schema", ())?,
|
28
|
+
name: val.funcall("name", ())?,
|
29
|
+
alias: val.funcall("alias", ())?,
|
30
|
+
})
|
31
|
+
} else {
|
32
|
+
Err(Error::new(
|
33
|
+
magnus::exception::type_error(),
|
34
|
+
format!(
|
35
|
+
"No implicit conversion of {} into SqlInsight::TableReference",
|
36
|
+
val.class()
|
37
|
+
),
|
38
|
+
))
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
impl fmt::Display for RbTableReferenceInner {
|
44
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
45
|
+
let mut parts = Vec::new();
|
46
|
+
if let Some(catalog) = &self.catalog {
|
47
|
+
parts.push(catalog.to_string());
|
48
|
+
}
|
49
|
+
if let Some(schema) = &self.schema {
|
50
|
+
parts.push(schema.to_string());
|
51
|
+
}
|
52
|
+
parts.push(self.name.to_string());
|
53
|
+
let table = parts.join(".");
|
54
|
+
if let Some(alias) = &self.alias {
|
55
|
+
write!(f, "{} AS {}", table, alias)
|
56
|
+
} else {
|
57
|
+
write!(f, "{}", table)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
#[derive(Clone)]
|
63
|
+
#[magnus::wrap(class = "SqlInsight::TableReference")]
|
64
|
+
pub struct RbTableReference {
|
65
|
+
inner: RefCell<RbTableReferenceInner>,
|
66
|
+
}
|
67
|
+
|
68
|
+
impl TryConvert for RbTableReference {
|
69
|
+
fn try_convert(val: Value) -> Result<Self, Error> {
|
70
|
+
Ok(Self {
|
71
|
+
inner: RefCell::new(RbTableReferenceInner::try_convert(val)?),
|
72
|
+
})
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
unsafe impl TryConvertOwned for RbTableReference {}
|
77
|
+
|
78
|
+
unsafe impl IntoValueFromNative for RbTableReference {}
|
79
|
+
|
80
|
+
impl Default for RbTableReference {
|
81
|
+
fn default() -> Self {
|
82
|
+
Self {
|
83
|
+
inner: RefCell::new(RbTableReferenceInner::default()),
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
impl RbTableReference {
|
89
|
+
pub fn new(
|
90
|
+
catalog: Option<&RbIdent>,
|
91
|
+
schema: Option<&RbIdent>,
|
92
|
+
name: &RbIdent,
|
93
|
+
alias: Option<&RbIdent>,
|
94
|
+
) -> Self {
|
95
|
+
Self {
|
96
|
+
inner: RbTableReferenceInner {
|
97
|
+
catalog: catalog.cloned(),
|
98
|
+
schema: schema.cloned(),
|
99
|
+
name: name.clone(),
|
100
|
+
alias: alias.cloned(),
|
101
|
+
}
|
102
|
+
.into(),
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
pub fn from_table_reference(table_reference: &TableReference) -> Self {
|
107
|
+
Self {
|
108
|
+
inner: RefCell::new(RbTableReferenceInner {
|
109
|
+
catalog: table_reference
|
110
|
+
.catalog
|
111
|
+
.clone()
|
112
|
+
.map(|ident| RbIdent::from_ident(&ident)),
|
113
|
+
schema: table_reference
|
114
|
+
.schema
|
115
|
+
.clone()
|
116
|
+
.map(|ident| RbIdent::from_ident(&ident)),
|
117
|
+
name: RbIdent::from_ident(&table_reference.name),
|
118
|
+
alias: table_reference
|
119
|
+
.alias
|
120
|
+
.clone()
|
121
|
+
.map(|ident| RbIdent::from_ident(&ident)),
|
122
|
+
}),
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
fn catalog(&self) -> Option<RbIdent> {
|
127
|
+
self.inner.borrow().catalog.clone()
|
128
|
+
}
|
129
|
+
|
130
|
+
fn set_catalog(&self, catalog: Option<&RbIdent>) {
|
131
|
+
self.inner.borrow_mut().catalog = catalog.cloned();
|
132
|
+
}
|
133
|
+
|
134
|
+
fn schema(&self) -> Option<RbIdent> {
|
135
|
+
self.inner.borrow().schema.clone()
|
136
|
+
}
|
137
|
+
|
138
|
+
fn set_schema(&self, schema: Option<&RbIdent>) {
|
139
|
+
self.inner.borrow_mut().schema = schema.cloned();
|
140
|
+
}
|
141
|
+
|
142
|
+
fn name(&self) -> RbIdent {
|
143
|
+
self.inner.borrow().name.clone()
|
144
|
+
}
|
145
|
+
|
146
|
+
fn set_name(&self, name: &RbIdent) {
|
147
|
+
self.inner.borrow_mut().name = name.clone();
|
148
|
+
}
|
149
|
+
|
150
|
+
fn alias(&self) -> Option<RbIdent> {
|
151
|
+
self.inner.borrow().alias.clone()
|
152
|
+
}
|
153
|
+
|
154
|
+
fn set_alias(&self, alias: Option<&RbIdent>) {
|
155
|
+
self.inner.borrow_mut().alias = alias.cloned();
|
156
|
+
}
|
157
|
+
|
158
|
+
fn to_s(&self) -> String {
|
159
|
+
self.inner.borrow().to_string()
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
pub fn init() -> Result<(), Error> {
|
164
|
+
let class = root().define_class("TableReference", class::object())?;
|
165
|
+
class.define_singleton_method("new", function!(RbTableReference::new, 4))?;
|
166
|
+
class.define_method("catalog", method!(RbTableReference::catalog, 0))?;
|
167
|
+
class.define_method("catalog=", method!(RbTableReference::set_catalog, 1))?;
|
168
|
+
class.define_method("schema", method!(RbTableReference::schema, 0))?;
|
169
|
+
class.define_method("schema=", method!(RbTableReference::set_schema, 1))?;
|
170
|
+
class.define_method("name", method!(RbTableReference::name, 0))?;
|
171
|
+
class.define_method("name=", method!(RbTableReference::set_name, 1))?;
|
172
|
+
class.define_method("alias", method!(RbTableReference::alias, 0))?;
|
173
|
+
class.define_method("alias=", method!(RbTableReference::set_alias, 1))?;
|
174
|
+
class.define_method("to_s", method!(RbTableReference::to_s, 0))?;
|
175
|
+
Ok(())
|
176
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
use crate::ruby_api::{root, RbTableReference};
|
2
|
+
use magnus::{class, function, method, Error, IntoValueFromNative, Module, Object, RArray};
|
3
|
+
use sql_insight::Tables;
|
4
|
+
use std::cell::RefCell;
|
5
|
+
|
6
|
+
#[derive(Default, Clone)]
|
7
|
+
struct RbTablesInner {
|
8
|
+
tables: Vec<RbTableReference>,
|
9
|
+
}
|
10
|
+
|
11
|
+
impl RbTablesInner {
|
12
|
+
pub fn new(tables: RArray) -> Result<Self, Error> {
|
13
|
+
Ok(Self {
|
14
|
+
tables: tables.to_vec::<RbTableReference>()?,
|
15
|
+
})
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
#[magnus::wrap(class = "SqlInsight::Tables")]
|
20
|
+
pub struct RbTables {
|
21
|
+
inner: RefCell<RbTablesInner>,
|
22
|
+
}
|
23
|
+
|
24
|
+
unsafe impl IntoValueFromNative for RbTables {}
|
25
|
+
|
26
|
+
impl Default for RbTables {
|
27
|
+
fn default() -> Self {
|
28
|
+
Self {
|
29
|
+
inner: RefCell::new(RbTablesInner::default()),
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
impl RbTables {
|
35
|
+
pub fn new(tables: RArray) -> Result<Self, Error> {
|
36
|
+
Ok(Self {
|
37
|
+
inner: RefCell::new(RbTablesInner::new(tables)?),
|
38
|
+
})
|
39
|
+
}
|
40
|
+
|
41
|
+
pub fn from_tables(tables: &Tables) -> RbTables {
|
42
|
+
RbTables {
|
43
|
+
inner: RefCell::new(RbTablesInner {
|
44
|
+
tables: tables
|
45
|
+
.0
|
46
|
+
.iter()
|
47
|
+
.map(RbTableReference::from_table_reference)
|
48
|
+
.collect(),
|
49
|
+
}),
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
fn tables(&self) -> RArray {
|
54
|
+
RArray::from_vec(self.inner.borrow().tables.clone())
|
55
|
+
}
|
56
|
+
|
57
|
+
fn set_tables(&self, tables: RArray) -> Result<(), Error> {
|
58
|
+
self.inner.borrow_mut().tables = tables.to_vec::<RbTableReference>()?;
|
59
|
+
Ok(())
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
pub fn init() -> Result<(), Error> {
|
64
|
+
let class = root().define_class("Tables", class::object())?;
|
65
|
+
class.define_singleton_method("new", function!(RbTables::new, 1))?;
|
66
|
+
class.define_method("tables", method!(RbTables::tables, 0))?;
|
67
|
+
class.define_method("tables=", method!(RbTables::set_tables, 1))?;
|
68
|
+
Ok(())
|
69
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SqlInsight
|
3
|
+
module Dialect
|
4
|
+
MYSQL = 'MySQL'
|
5
|
+
POSTGRESQL = 'PostgreSQL'
|
6
|
+
SQLITE = 'SQLite'
|
7
|
+
SQLSERVER = 'MsSQL'
|
8
|
+
GENERIC = 'Generic'
|
9
|
+
HIVE = 'Hive'
|
10
|
+
SNOWFLAKE = 'Snowflake'
|
11
|
+
REDSHIFT = 'Uedshift'
|
12
|
+
CLICKHOUSE = 'Clickhouse'
|
13
|
+
BIGQUERY = 'BigQuery'
|
14
|
+
ANSI = 'ANSI'
|
15
|
+
DUCKDB = 'DuckDB'
|
16
|
+
end
|
17
|
+
end
|
data/lib/sql_insight.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sql_insight/version'
|
4
|
+
require_relative 'sql_insight/dialect'
|
5
|
+
require_relative 'sql_insight/errors'
|
6
|
+
|
7
|
+
# https://github.com/rake-compiler/rake-compiler/blob/master/README.md
|
8
|
+
# Technique to lookup the fat binaries first, and then lookup the gems compiled by the end user.
|
9
|
+
begin
|
10
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
11
|
+
require_relative "sql_insight/#{Regexp.last_match(1)}/sql_insight"
|
12
|
+
rescue LoadError
|
13
|
+
require_relative 'sql_insight/sql_insight'
|
14
|
+
end
|
15
|
+
|
16
|
+
module SqlInsight
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sql_insight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takahiro Ebato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb_sys
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.90
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.90
|
27
|
+
description: Ruby bindings for the sql-insight, a utility for SQL query analysis and
|
28
|
+
transformation supporting various SQL dialects
|
29
|
+
email:
|
30
|
+
- takahiro.ebato@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions:
|
33
|
+
- ext/sql_insight/extconf.rb
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Cargo.lock
|
37
|
+
- Cargo.toml
|
38
|
+
- ext/sql_insight/Cargo.toml
|
39
|
+
- ext/sql_insight/extconf.rb
|
40
|
+
- ext/sql_insight/src/errors.rs
|
41
|
+
- ext/sql_insight/src/lib.rs
|
42
|
+
- ext/sql_insight/src/ruby_api/crud_tables.rs
|
43
|
+
- ext/sql_insight/src/ruby_api/ident.rs
|
44
|
+
- ext/sql_insight/src/ruby_api/mod.rs
|
45
|
+
- ext/sql_insight/src/ruby_api/pub_funcs.rs
|
46
|
+
- ext/sql_insight/src/ruby_api/table_reference.rs
|
47
|
+
- ext/sql_insight/src/ruby_api/tables.rs
|
48
|
+
- lib/sql_insight.rb
|
49
|
+
- lib/sql_insight/dialect.rb
|
50
|
+
- lib/sql_insight/errors.rb
|
51
|
+
- lib/sql_insight/version.rb
|
52
|
+
homepage: https://github.com/takaebato/sql-insight-rb
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata:
|
56
|
+
homepage_uri: https://github.com/takaebato/sql-insight-rb
|
57
|
+
source_code_uri: https://github.com/takaebato/sql-insight-rb
|
58
|
+
changelog_uri: https://github.com/takaebato/sql-insight-rb/blob/master/CHANGELOG.md
|
59
|
+
rubygems_mfa_required: 'true'
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.2
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.3.22
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.5.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Ruby bindings for the sql-insight, a utility for SQL query analysis and transformation
|
79
|
+
test_files: []
|