pg_conn 0.38.1 → 0.39.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: a643fd02f7ad3296edd58d09adf028634f865d24e1eccad2ad1cdd70bc222eaf
4
- data.tar.gz: e07e79bde8c45423493fea5028bf8f920fede7b313efc25ff2883f77e3316540
3
+ metadata.gz: ace2859257bedbbdeb816bfb04d9d7e23d686942c328e0d521568b6f4fc57e90
4
+ data.tar.gz: b803feaaaa619668cf00f57d2c5ffd072f04a149e144eafb061b85d4bf4cfad4
5
5
  SHA512:
6
- metadata.gz: 452b57a9bbf438d9158eb32a1c21a951fe57024232a33c4c4d4c7409d2c44e66649ae393f03620825a25a550650341f6cb6b6e265b726a5113bb2e5e270d65b6
7
- data.tar.gz: 4bdfd665f9285206af32bfa537157a2aeee37400d271477c2a1fb26387b7f98974072c99540a8dc211822e90f8f5a72b6980ac74539379c483c8e985d0ec6b52
6
+ metadata.gz: b2b913861f23ed8db39f8d521571bb054c3ed9ca1526b800c5f4982f9b4a9f285cc60b17dc59194b2df7cc2147019faaef7b838a4e10d4e8659941adb6fddde9
7
+ data.tar.gz: aac27bc4b8e7881ded4fdfe350a98be3de919052b9b5fcbca0d6767573dd9592d4922e3b2da968860b146d451b05bb96937e7344941d58048a104c5b8bda9081
@@ -152,7 +152,7 @@ module PgConn
152
152
  end
153
153
  end
154
154
 
155
- # Set the serial value for the table
155
+ # Set current serial value for the table. The sequence is marked unused if value is nil
156
156
  def set_serial(schema, table, value)
157
157
  uid = "#{schema}.#{table}"
158
158
  seq = sequence(schema, table) or raise ArgumentError, "Table #{uid} does not have a sequence"
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.38.1"
2
+ VERSION = "0.39.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -664,9 +664,11 @@ module PgConn
664
664
 
665
665
  # TODO: #group - same as table but partitions a table on the given keys
666
666
  # returning a map from key to array of records
667
-
667
+ #
668
668
  # TODO: An #array method that returns a map from id to tuple. Hmm... almost
669
669
  # the same as #map
670
+ #
671
+ # TODO: Swap key and query arguments
670
672
 
671
673
  # Return a hash from the record id column to an OpenStruct representation
672
674
  # of the record. If the :key_column option is defined it will be used
@@ -718,6 +720,7 @@ module PgConn
718
720
  # group-by on the key and array_agg on the remaining values. The value is
719
721
  # an array of tuples if the query has more than one value field and an
720
722
  # array of values if there is only one value field
723
+ #
721
724
  def multimap(query, key = nil, symbol: false)
722
725
  r = pg_exec(query)
723
726
  begin
@@ -736,6 +739,14 @@ module PgConn
736
739
  h
737
740
  end
738
741
 
742
+ # TODO
743
+ # structset
744
+ # recordset
745
+ # structmap
746
+ # recormap
747
+ # multistruct
748
+ # multirecord
749
+
739
750
  # Return the value of calling the given postgres function. It dynamically
740
751
  # detects the structure of the result and return a value or an array of
741
752
  # values if the result contained only one column (like #value or #values),
@@ -777,9 +788,9 @@ module PgConn
777
788
 
778
789
  # :call-seq:
779
790
  # insert(table, record|records)
780
- # insert(table, fields, record|records|tuples)
791
+ # insert(table, fields, record|records|tuples|values)
781
792
  # insert(schema, table, record|records)
782
- # insert(schema, table, fields, record|records|tuples)
793
+ # insert(schema, table, fields, record|records|tuples|values)
783
794
  #
784
795
  # Insert record(s) in table and return id(s)
785
796
  #
@@ -818,7 +829,8 @@ module PgConn
818
829
  fields ||= data.first.keys
819
830
  tuples = data.map { |record| fields.map { |field| record[field] } }
820
831
  else
821
- raise ArgumentError
832
+ fields.size == 1 or raise ArgumentError, "Illegal number of fields, expected exactly one"
833
+ tuples = data.map { |e| [e] }
822
834
  end
823
835
  elsif data.is_a?(Hash)
824
836
  method = upsert ? :value? : :value # The pg_conn method when only one record is inserted
@@ -913,6 +925,7 @@ module PgConn
913
925
  #
914
926
  # TODO: Make sure the transaction stack is emptied on postgres errors
915
927
  def exec(sql, commit: true, fail: true, silent: self.silent)
928
+ return nil if sql.nil? || Array[sql].empty?
916
929
  transaction(commit: commit) {
917
930
  begin
918
931
  execute(sql, fail: fail, silent: silent)
@@ -928,6 +941,7 @@ module PgConn
928
941
  # #execute? method because any failure rolls back the whole transaction
929
942
  # stack. TODO: Check which exceptions that should be captured
930
943
  def exec?(sql, commit: true, silent: true)
944
+ return nil if sql.nil? || Array[sql].empty?
931
945
  begin
932
946
  exec(sql, commit: commit, fail: true, silent: silent)
933
947
  rescue PG::Error
@@ -945,6 +959,7 @@ module PgConn
945
959
  #
946
960
  # TODO: Handle postgres exceptions wrt transaction state and stack
947
961
  def execute(sql, fail: true, silent: self.silent)
962
+ return nil if sql.nil? || Array[sql].empty?
948
963
  if @pg_connection
949
964
  begin
950
965
  pg_exec(sql, silent: silent)&.cmd_tuples
@@ -1320,7 +1335,7 @@ module PgConn
1320
1335
  #
1321
1336
  # Execute statement(s) on the server. If the argument is an array of
1322
1337
  # commands, the commands are concatenated with ';' before being sent to the
1323
- # server. #pg_exec returns a PG::Result object or nil if +arg+ was empty
1338
+ # server. #pg_exec returns a PG::Result object or nil if +arg+ was nil or empty
1324
1339
  #
1325
1340
  # Postgres errors are passed through and #error and #err set to the last
1326
1341
  # statement's SQL errors or nil if it succeeded
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.38.1
4
+ version: 0.39.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen