pg_conn 0.41.0 → 0.42.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pg_conn/version.rb +1 -1
  3. data/lib/pg_conn.rb +36 -21
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fb72128df77cad4c2a3e5992f2d72a727af4b57fc898b8c2f7102ebd8df7ebd
4
- data.tar.gz: ced62377173f5c33d428bec72c321a934947b5f4a24cac8467ad0c0955131a32
3
+ metadata.gz: 8d9aafa29dec55b879562f1ee2925322ccbde2c829d1c23c0529d41c171210e4
4
+ data.tar.gz: de71188ab165e6c0d3b8d1d1e947e5ea9deb0615287da2467dfffa7ae048d910
5
5
  SHA512:
6
- metadata.gz: 0becdbeef4a4feb64c550e03d167143f59dda2a6eb986119eababab944cb22fefd36b13fd6fe2a4ea2866c8297bf2000f8683a3a86a47753a3cd462f214e007f
7
- data.tar.gz: 829f2be06bfe9a278544b5c909841c418e3b248e8287dad640f43c28039f2dfc3ad028052f435c20248187774ddbbcbdd1d6df412b6b1f52fd481d5b5bfa2ce8
6
+ metadata.gz: 7852a85c9a0b0ec2d31429a800cc1362e0c42d9a143cff80dfc47f81c2cad4fa3517777e91143f2a4876148b641a252d888e9316f53642af8f341772bce2bf8f
7
+ data.tar.gz: faf876c344f385b50f6813249114df1cec630ce85313517abb3e8a5a521524d14746fd58bed085cfc098298d0514bfa1c5bf17fa84fce0cb06790376a50699d4
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.41.0"
2
+ VERSION = "0.42.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -887,12 +887,12 @@ module PgConn
887
887
  end
888
888
 
889
889
  # Execute SQL statement using either :value or :values depending on data arity
890
- self.send method, %(
890
+ self.send method, <<~SQL
891
891
  insert into #{table} (#{quote_identifiers(fields)})
892
892
  values #{quote_tuples(tuples)}
893
893
  #{upsert_sql}
894
894
  returning id
895
- )
895
+ SQL
896
896
  end
897
897
 
898
898
  # Use upsert. Currently only 'on conflict do nothing' is supported
@@ -1068,16 +1068,6 @@ module PgConn
1068
1068
 
1069
1069
  # TODO: Move to TransactionMethods
1070
1070
 
1071
- def commit()
1072
- if transaction?
1073
- pop_transaction(fail: false)
1074
- else
1075
- pg_exec("commit")
1076
- end
1077
- end
1078
-
1079
- def rollback() raise Rollback end
1080
-
1081
1071
  # True if a transaction is in progress
1082
1072
  #
1083
1073
  # Note that this requires all transactions to be started using PgConn's
@@ -1113,6 +1103,7 @@ module PgConn
1113
1103
  end
1114
1104
  end
1115
1105
 
1106
+ # FIXME :exception is unused
1116
1107
  def pop_transaction(commit: true, fail: true, exception: true)
1117
1108
  if transaction?
1118
1109
  if savepoint = @savepoints.pop
@@ -1156,13 +1147,11 @@ module PgConn
1156
1147
 
1157
1148
  # Start a transaction. If called with a block, the block is executed within
1158
1149
  # a transaction that is auto-committed if the commit option is true (the
1159
- # default). #transaction returns the result of the block or nil if no block
1160
- # was given
1161
- #
1162
- # The transaction can be rolled back inside the block by raising a
1163
- # PgConn::Rollback exception in which case #transaction returns nil. Note
1164
- # that the transaction timestamp is set to the start of the first
1165
- # transaction even if transactions are nested
1150
+ # default). The transaction is rolled back automatically if :commit is
1151
+ # false or if a PgConn::Rollback is raised with the block. #transaction
1152
+ # returns the result of the block or nil if no block was given. Note that
1153
+ # the transaction timestamp is set to the start of the first transaction
1154
+ # even if transactions are nested
1166
1155
  #
1167
1156
  # FIXME: There is some strange problem in rspec where #insert handles
1168
1157
  # an exception correctly while #exec, #execute, and #transaction does not
@@ -1187,6 +1176,19 @@ module PgConn
1187
1176
  end
1188
1177
  end
1189
1178
 
1179
+ # The flow to global transactions is
1180
+ #
1181
+ # conn.transaction # Starts a transaction
1182
+ # ...
1183
+ # if ok
1184
+ # conn.commit
1185
+ # else
1186
+ # conn.rollback
1187
+ # end
1188
+ #
1189
+ def commit() pop_transaction(fail: false) end
1190
+ def rollback() pop_transaction(commit: false, fail: false) end
1191
+
1190
1192
  def dump(*query)
1191
1193
  records = self.records(*query)
1192
1194
 
@@ -1264,7 +1266,18 @@ module PgConn
1264
1266
  datas = [datas] if !array
1265
1267
 
1266
1268
  pg_type = [schema_name, type].compact.join('.')
1267
- fields = self.values(%(
1269
+ # fields = self.values(%(
1270
+ # select attname
1271
+ # from pg_attribute
1272
+ # where
1273
+ # attrelid = '#{pg_type}'::regclass
1274
+ # and attnum > 0
1275
+ # and not attisdropped
1276
+ # order by attnum
1277
+ # )).map(&:to_sym)
1278
+
1279
+
1280
+ sql = <<~SQL
1268
1281
  select attname
1269
1282
  from pg_attribute
1270
1283
  where
@@ -1272,7 +1285,9 @@ module PgConn
1272
1285
  and attnum > 0
1273
1286
  and not attisdropped
1274
1287
  order by attnum
1275
- )).map(&:to_sym)
1288
+ SQL
1289
+
1290
+ fields = self.values(sql).map(&:to_sym)
1276
1291
 
1277
1292
  literals = datas.map { |data|
1278
1293
  values =
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.41.0
4
+ version: 0.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen