json2sql 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/json2sql/query_policy.rb +1 -3
- data/lib/json2sql/select_model.rb +40 -5
- data/lib/json2sql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7388641e5f74990b482a145d6d096ae5612ebb2b8f8def9761c73d193b56c492
|
|
4
|
+
data.tar.gz: 82fa2ae894923ca9d983b7d082bdd4b33fdab7cfb23f96ba3b8c3ab93052e04a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e109f0025272b5f8387b6d7f457cd0cd59d3271788b160bd7612f0130abf792d46cab329ead1474e8a201f7481a40f449a66d86f5db759c147eda3447411ffc6
|
|
7
|
+
data.tar.gz: ff26c02113459a4f8000ab6a59ab7013a1e22546d05fc901359e5b663de57ffc203b90a73c7288d1d737ace6e3385831199249502c24965715be7c8a27712ec1
|
|
@@ -5,7 +5,7 @@ module Json2sql
|
|
|
5
5
|
# Parameters:
|
|
6
6
|
# mode: :allow (default) — only tables listed in `tables:` are accessible.
|
|
7
7
|
# Tables absent from `tables:` are blocked entirely.
|
|
8
|
-
# Empty `tables:` =
|
|
8
|
+
# Empty `tables:` = all tables blocked.
|
|
9
9
|
# :deny — all tables pass. After column filtering, tables
|
|
10
10
|
# with no remaining accessible columns are removed.
|
|
11
11
|
# Same rule applies to children and parents.
|
|
@@ -106,8 +106,6 @@ module Json2sql
|
|
|
106
106
|
|
|
107
107
|
tables = config.is_a?(Hash) ? config : {}
|
|
108
108
|
|
|
109
|
-
return if tables.empty?
|
|
110
|
-
|
|
111
109
|
params.select! { |table, _| tables.key?(table) }
|
|
112
110
|
end
|
|
113
111
|
|
|
@@ -325,15 +325,24 @@ module Json2sql
|
|
|
325
325
|
|
|
326
326
|
function = Sanitizer.keyword(column["function"].to_s)
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
params = column["params"]
|
|
329
329
|
|
|
330
|
-
|
|
330
|
+
return build_function_cast(params) if function.upcase == "CAST"
|
|
331
|
+
|
|
332
|
+
build_function_default(function, params)
|
|
333
|
+
end
|
|
331
334
|
|
|
332
|
-
|
|
335
|
+
def build_function_default(function, params)
|
|
333
336
|
|
|
334
|
-
|
|
337
|
+
expression = +""
|
|
338
|
+
|
|
339
|
+
expression << function << "("
|
|
340
|
+
|
|
341
|
+
glue = false
|
|
335
342
|
|
|
336
|
-
|
|
343
|
+
if params.is_a?(Array)
|
|
344
|
+
|
|
345
|
+
params.each do |param|
|
|
337
346
|
|
|
338
347
|
next unless param.is_a?(String) || param.is_a?(Symbol)
|
|
339
348
|
|
|
@@ -350,6 +359,32 @@ module Json2sql
|
|
|
350
359
|
expression
|
|
351
360
|
end
|
|
352
361
|
|
|
362
|
+
# Supports function payload: {"function"=>"CAST", "params"=>["id", "CHAR"]}
|
|
363
|
+
# and generic cast targets like SIGNED/UNSIGNED/CHAR.
|
|
364
|
+
|
|
365
|
+
def build_function_cast(params)
|
|
366
|
+
|
|
367
|
+
return +"NULL" unless params.is_a?(Array) && params.length >= 2
|
|
368
|
+
|
|
369
|
+
source = params[0]
|
|
370
|
+
|
|
371
|
+
return +"NULL" unless source.is_a?(String) || source.is_a?(Symbol)
|
|
372
|
+
|
|
373
|
+
cast_type = Sanitizer.keyword(params[1].to_s).upcase
|
|
374
|
+
|
|
375
|
+
return +"NULL" if cast_type.empty?
|
|
376
|
+
|
|
377
|
+
expression = +"CAST("
|
|
378
|
+
|
|
379
|
+
expression << Sanitizer.keyword_wrap(@table) << "."
|
|
380
|
+
|
|
381
|
+
expression << Sanitizer.keyword_wrap(source.to_s)
|
|
382
|
+
|
|
383
|
+
expression << " AS " << cast_type << ")"
|
|
384
|
+
|
|
385
|
+
expression
|
|
386
|
+
end
|
|
387
|
+
|
|
353
388
|
def build_order(params)
|
|
354
389
|
|
|
355
390
|
order = params["order"]
|
data/lib/json2sql/version.rb
CHANGED