active_sql_bindings 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_sql_bindings.rb +11 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14e940cc423d658ac101bd34659de352e16fb6b5abc0059c3a893a1456539ef7
4
- data.tar.gz: f4c1e282d3c340b457ff476bea204472224bf2df04d5e9cf629ad5b035e309bd
3
+ metadata.gz: f239b3e4d3fd059d41919b16985b560bc34ab11054a39e142aa2b3bdb42a443d
4
+ data.tar.gz: 87a56fa5a5e000fdda4c545885a0048c8c4d42fd26d3a41b604836db37c9a4ef
5
5
  SHA512:
6
- metadata.gz: 3c68fb0a3786594fe85e3c90a1be53a00d39281e63f9ac9addcd7132facf165d0d2bf4b5cef927767c04e1ed8d4e2ecbe492848a512ef719ba5ec19a11b014a9
7
- data.tar.gz: 9320f4b9c8667c16367c3c9794c025f9618e46bdb3ed1d2992b24828a14ad779b486945f27f8b2be3c50c8c80cf4328a6bd497445cc9876c250f18910c1df846
6
+ metadata.gz: ae7f17113f919ee5e61fb7c13f7ea285e251c21dc3700176c23e99bb0c26cb8f5d1e2d156861ac7f5cebc15296c173ac02c426ceaa44224b2a95481323c2b1d4
7
+ data.tar.gz: fda855c717069c7c985b4d37854b5a419dc1af850a36d0d5c3e9896eec8b7da9b3e609b6bba38ed24b3d99a30946a13a64b15c87b6bbfcbb71d32f4a8c18b95e
@@ -31,15 +31,19 @@ class ActiveSqlBindings
31
31
  end
32
32
 
33
33
  # Execute query, convert to hash with symbol keys
34
- result = ActiveRecord::Base.connection.exec_query(sql, 'SQL', bindings).map(&:symbolize_keys)
34
+ sql_result = ActiveRecord::Base.connection.exec_query(sql, 'SQL', bindings)
35
35
 
36
- # Convert JSON data to hash
37
- result.map do |v|
38
- next if v.nil?
36
+ # Find fields JSON/JSONb type
37
+ json_fields = sql_result.column_types.select { |_k, v| v.type == :json || v.type == :jsonb }.keys
39
38
 
40
- v.each do |key, val|
41
- v[key] = json_to_hash(val)
42
- end
39
+ # Convert JSON data to hash
40
+ sql_result.map do |v|
41
+ v.map do |key, value|
42
+ [
43
+ key.to_sym,
44
+ json_fields.include?(key) ? json_to_hash(value) : value
45
+ ]
46
+ end.to_h
43
47
  end
44
48
  end
45
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_sql_bindings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilevsky Kirill