pg_conn 0.45.0 → 0.46.0
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/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +15 -7
- 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: bc9f98c5804eb386c76e607d056c12ead0e44feb0df8dcabb85b3c057d824868
|
|
4
|
+
data.tar.gz: d0318211117d792acb5936b6d2b10557548fe491a030898cfc7ed55dfd901ad5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e2845bab10f1ff11373d43dfda7ad4650c38eff52fc6f874450fd4a9a294bd290be36d9922260ae2d1429bb218f62116b4a15eb521bd48ceaaa4381ac9685e1
|
|
7
|
+
data.tar.gz: c9d413eabf917f15c64dfd2165229203ebc3ca1dbef32ea42858934812dffd1ce257abe821c9a58fa864feaa26348fc76c86980599dad9287f0fc5aa44660cb6
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
|
@@ -832,11 +832,11 @@ module PgConn
|
|
|
832
832
|
end
|
|
833
833
|
|
|
834
834
|
# :call-seq:
|
|
835
|
-
# insert(table, record|records)
|
|
836
|
-
# insert(table, fields, record|records|tuples|values)
|
|
835
|
+
# insert(table, struct|structs|record|records)
|
|
836
|
+
# insert(table, fields, struct|structs|record|records|tuples|values)
|
|
837
837
|
#
|
|
838
|
-
# insert(schema, table, record|records)
|
|
839
|
-
# insert(schema, table, fields, record|records|tuples|values)
|
|
838
|
+
# insert(schema, table, struct|structs|record|records)
|
|
839
|
+
# insert(schema, table, fields, struct|structs|record|records|tuples|values)
|
|
840
840
|
#
|
|
841
841
|
# Insert record(s) in table and return id(s)
|
|
842
842
|
#
|
|
@@ -874,12 +874,15 @@ module PgConn
|
|
|
874
874
|
method = :values # The pg_conn method when multiple records are inserted
|
|
875
875
|
if data.empty?
|
|
876
876
|
return []
|
|
877
|
-
elsif data.first.is_a?(Array) # Tuple (
|
|
877
|
+
elsif data.first.is_a?(Array) # Tuple (Array) element. Requires the 'fields' argument
|
|
878
878
|
fields or raise ArgumentError
|
|
879
879
|
tuples = data
|
|
880
|
-
elsif data.first.is_a?(Hash) # Hash element
|
|
880
|
+
elsif data.first.is_a?(Hash) # Record (Hash) element
|
|
881
881
|
fields ||= data.first.keys
|
|
882
882
|
tuples = data.map { |record| fields.map { |field| record[field] } }
|
|
883
|
+
elsif data.first.is_a?(OpenStruct)
|
|
884
|
+
fields ||= data.first.to_h.keys
|
|
885
|
+
tuples = data.map { |struct| hash = struct.to_h; fields.map { |field| hash[field] } }
|
|
883
886
|
else
|
|
884
887
|
fields.size == 1 or raise ArgumentError, "Illegal number of fields, expected exactly one"
|
|
885
888
|
tuples = data.map { |e| [e] }
|
|
@@ -888,6 +891,11 @@ module PgConn
|
|
|
888
891
|
method = upsert ? :value? : :value # The pg_conn method when only one record is inserted
|
|
889
892
|
fields ||= data.keys
|
|
890
893
|
tuples = [fields.map { |field| data[field] }]
|
|
894
|
+
elsif data.is_a?(OpenStruct)
|
|
895
|
+
method = upsert ? :value? : :value # The pg_conn method when only one record is inserted
|
|
896
|
+
hash = data.to_h
|
|
897
|
+
fields ||= hash.keys
|
|
898
|
+
tuples = [fields.map { |field| hash[field] }]
|
|
891
899
|
else
|
|
892
900
|
raise ArgumentError, "Illegal argument '#{data.inspect}'"
|
|
893
901
|
end
|
|
@@ -1286,7 +1294,7 @@ module PgConn
|
|
|
1286
1294
|
end
|
|
1287
1295
|
|
|
1288
1296
|
# Common implementation for #quote_record and #quote_records that avoids
|
|
1289
|
-
# querying the database multiple times or
|
|
1297
|
+
# querying the database multiple times or duplicating the code
|
|
1290
1298
|
#
|
|
1291
1299
|
# @data can be a Hash, Array, or OpenStruct. Hash keys must be symbols or
|
|
1292
1300
|
# strings, they belong to the same namespace so :k and "k" refer to the
|