json2sql 1.0.12 → 1.0.13
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/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: 6282183f873d4f4e32d0c0819c43ffe20ce53dbabd71bb44ba26b362edbaf9d7
|
|
4
|
+
data.tar.gz: 1aa18874f4bbfc9f1ac395b357babb98f3884f577f2fe8d3d81d7f647cbfc2ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e84fdd24a2efa2eb464d85df3a3ec3b8370d204bb4d64676dcb953e2777bb34d3bc0807eb0e2fc9c65ffb167911ce89a3c3606a7bcb66d20698b0e617801f81
|
|
7
|
+
data.tar.gz: 9b6f1b82866c8ff0d96af65439ed0a2b6f96592ecde63187b1d91ed27a513d92a3f57077c06862e2582f31342c62f18dabed2f08577a067f358760e5e07161c4
|
|
@@ -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