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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a1ea5e0f95c4a548b1bb9360e2adb5a4b5356992016d76b4babc16acb0d85c9
4
- data.tar.gz: '01873a86ae29993fd7b5e9902506b074333294207fa8ef6b4b8d122272bad4b6'
3
+ metadata.gz: 6282183f873d4f4e32d0c0819c43ffe20ce53dbabd71bb44ba26b362edbaf9d7
4
+ data.tar.gz: 1aa18874f4bbfc9f1ac395b357babb98f3884f577f2fe8d3d81d7f647cbfc2ba
5
5
  SHA512:
6
- metadata.gz: 01d567792598296fbeaa37e25a215a33a911fabcf8c847818a3f6c1dba59c9a9ef792ccd387f4728bbf2616a3135ff6a6246a637376e9b3940414c8127160ce6
7
- data.tar.gz: 0263df1d2046c256341c926b9dfece8bdedc9722e603153df64c7175884acf76bd66fe24f9de360177dcb97639444c6b32539d2eaec52cc91761d229ba426f23
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
- expression = +"#{function}("
328
+ params = column["params"]
329
329
 
330
- glue = false
330
+ return build_function_cast(params) if function.upcase == "CAST"
331
+
332
+ build_function_default(function, params)
333
+ end
331
334
 
332
- col_params = column["params"]
335
+ def build_function_default(function, params)
333
336
 
334
- if col_params.is_a?(Array)
337
+ expression = +""
338
+
339
+ expression << function << "("
340
+
341
+ glue = false
335
342
 
336
- col_params.each do |param|
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"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Json2sql
4
- VERSION = "1.0.12"
4
+ VERSION = "1.0.13"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json2sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago da Silva