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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1068edc8dc81b7b2b04eecbf4ae901c7777cfbdeec63855baa3db16fee6d1a83
4
- data.tar.gz: 694ed53ea67c15829d0c0788f76e7d45b00124acc158cb6aaa92205046a68c85
3
+ metadata.gz: bc9f98c5804eb386c76e607d056c12ead0e44feb0df8dcabb85b3c057d824868
4
+ data.tar.gz: d0318211117d792acb5936b6d2b10557548fe491a030898cfc7ed55dfd901ad5
5
5
  SHA512:
6
- metadata.gz: d7eadc60da62af57bf1b706cdc7ea8aa9361c20847e49cf16a9443dbda1434ae5ff185267c7e30e3c2a3da3cf35eaa3679e6d85bbdc8140325f40156bb94335b
7
- data.tar.gz: 783af32e37c31aed616b6d9fa60780d484b966b3e8e345d194e96edf4f576a199a16177e080b5d915ec4cba6d4458d86c09ceb5df00f2f5f33938a6a815826c8
6
+ metadata.gz: 6e2845bab10f1ff11373d43dfda7ad4650c38eff52fc6f874450fd4a9a294bd290be36d9922260ae2d1429bb218f62116b4a15eb521bd48ceaaa4381ac9685e1
7
+ data.tar.gz: c9d413eabf917f15c64dfd2165229203ebc3ca1dbef32ea42858934812dffd1ce257abe821c9a58fa864feaa26348fc76c86980599dad9287f0fc5aa44660cb6
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.45.0"
2
+ VERSION = "0.46.0"
3
3
  end
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 (array) element. Requires the 'fields' argument
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 duplication the code
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_conn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.0
4
+ version: 0.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen