json2sql 1.0.3 → 1.0.5

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: '081df2cfbe162d78f93d112d4566e0639af9770ba8f26b4cba40e98d518cf749'
4
- data.tar.gz: 45c1664023f707fe8c09a18a2d184d6af26ac199534ce92f6cb1b969a234a7e7
3
+ metadata.gz: 47b47f1de5a006ae89f030877af6c876d550ee0588efbe1561fc16910f08704c
4
+ data.tar.gz: 00262e8bad2ab2846a7bbb21a81d7554ca5b7e4eb776ba130f0e156eb84dacae
5
5
  SHA512:
6
- metadata.gz: 7fac86cfbbd4aca360ae717528e4bbb43a3d98e9e452e4e339f30a07d9cb19f11498cbd7ae9640509ce934dc2efc0aec401685e43bfd82e9e9ef4e17d768376f
7
- data.tar.gz: 01b3370c8936fde70bf803cb257095ae778e008fa63ca98b0eac8f28c2a0b430a0dfc8492aec4ec49eafa4adddd49464e63306d752426e1058a9ec21ed0a258a
6
+ metadata.gz: cb923a2ad4a85e7925b3ea44dc7b6f5fab6f05c18ebbcf9fa6cb03f6352f31d6e791fae45651177360b4fd903f596b102fd5e50011569b01f6315d645eaccb2c
7
+ data.tar.gz: 3e2e61950bf948b1fe4028a2fd7b21c64489568be3198474cfed51ac65dda748cc6f48e864ebe4040cd35e59d22b2e7a736f3b0b703f6d6c6d0a4746dbeb865e
@@ -175,6 +175,25 @@ module Json2sql
175
175
 
176
176
  columns.each do |column|
177
177
 
178
+ if column.is_a?(Hash)
179
+
180
+ alias_name = column["alias"].to_s
181
+
182
+ next if alias_name.empty?
183
+
184
+ @sql << ", " if @sep
185
+
186
+ @sep = true
187
+
188
+ @sql << build_function(column)
189
+
190
+ @sql << " AS "
191
+
192
+ @sql << Sanitizer.keyword_wrap(alias_name)
193
+
194
+ next
195
+ end
196
+
178
197
  next unless column.is_a?(String) || column.is_a?(Symbol)
179
198
 
180
199
  @sql << ", " if @sep
@@ -197,6 +216,25 @@ module Json2sql
197
216
 
198
217
  columns.each do |column|
199
218
 
219
+ if column.is_a?(Hash)
220
+
221
+ alias_name = column["alias"].to_s
222
+
223
+ next if alias_name.empty?
224
+
225
+ @sql << ", " if @sep
226
+
227
+ @sep = true
228
+
229
+ @sql << Sanitizer.keyword_wrap(alias_name, "'")
230
+
231
+ @sql << ", "
232
+
233
+ @sql << build_function(column)
234
+
235
+ next
236
+ end
237
+
200
238
  next unless column.is_a?(String) || column.is_a?(Symbol)
201
239
 
202
240
  @sql << ", " if @sep
@@ -277,6 +315,37 @@ module Json2sql
277
315
  end
278
316
  end
279
317
 
318
+ # Builds a SQL function call expression: FUNC_NAME(`table`.`col1`, ...)
319
+
320
+ def build_function(column)
321
+
322
+ function = Sanitizer.keyword(column["function"].to_s)
323
+
324
+ expression = +"#{function}("
325
+
326
+ glue = false
327
+
328
+ col_params = column["params"]
329
+
330
+ if col_params.is_a?(Array)
331
+
332
+ col_params.each do |param|
333
+
334
+ next unless param.is_a?(String) || param.is_a?(Symbol)
335
+
336
+ expression << ", " if glue
337
+
338
+ glue = true
339
+
340
+ expression << Sanitizer.keyword_wrap(@table) << "." << Sanitizer.keyword_wrap(param.to_s)
341
+ end
342
+ end
343
+
344
+ expression << ")"
345
+
346
+ expression
347
+ end
348
+
280
349
  def build_order(params)
281
350
 
282
351
  order = params["order"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Json2sql
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.5"
5
5
  end
@@ -370,7 +370,6 @@ module Json2sql
370
370
  def get_action(action)
371
371
 
372
372
  case action
373
- when "=", "<", ">", "<=", ">=", "!=", "<>" then action
374
373
  when "in" then "IN"
375
374
  when "!in" then "NOT IN"
376
375
  when "like" then "LIKE"
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.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago da Silva