pg_conn 0.41.1 → 0.42.1

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: 3c3ec749b3c1c7937e8c4fb0869c9ae3ef20549585f5385b44b1bf1f59275f02
4
- data.tar.gz: cc620bc609a52ccf03d1976c8c13d5c37cb5d6de1d5edacb44b1a5fb3e334f98
3
+ metadata.gz: 1885ef3f2d7a35d098e8bf78136148634c7b2d828b33477235a3cd1e38765df6
4
+ data.tar.gz: 853369281c40c6c6fc60a80785f6166d27fcc500cf7f1e216e348adfed778c30
5
5
  SHA512:
6
- metadata.gz: f58e940330fe87d38ece2ed98516b2e0ba21b5c14c6f3f561bd3339278176182bd5201e5529d3071a6318c02b8e6f5031a9be7b8b491af0e95ac299c09b8769f
7
- data.tar.gz: fa5b3de455427cf6885c2d2757121465e312280f17a22da665fef5d232baa2406b0a14b2babd8ae6ebe22f04bb1d8f4d029d3f93c79be9c58b6ea16d6f9029be
6
+ metadata.gz: b839c16a46f84ae89f8bb941d08972f24edd3f3bf777d17197ad1cdaf5bc8e5ab368135e8222dac202a3b3d670c04c027e7a9afff00a0b851af8d899f93baef9
7
+ data.tar.gz: a9171073a19b5ed326eaf58a4d4fbcd4b61fad8bc1154e0c000e99b61c94b068ba8f70c14e773bd9eb455d0d7dd111a2bac02c4646c07b1bd01843d134338cb4
@@ -22,15 +22,15 @@ module PgConn
22
22
  def create(schema, authorization: nil)
23
23
  authorization_clause = authorization ? "authorization #{authorization}" : nil
24
24
  stmt = ["create schema", schema, authorization_clause].compact.join(" ")
25
- conn.exec stmt
25
+ conn.execute stmt
26
26
  end
27
27
 
28
28
  # Drop schema
29
29
  def drop(schema, cascade: false)
30
30
  if cascade
31
- conn.exec "drop schema if exists #{schema} cascade"
31
+ conn.execute "drop schema if exists #{schema} cascade"
32
32
  else
33
- conn.exec "drop schema if exists #{schema}"
33
+ conn.execute "drop schema if exists #{schema}"
34
34
  end
35
35
  true
36
36
  end
@@ -39,10 +39,10 @@ module PgConn
39
39
  # functions and procedures TODO)
40
40
  def empty!(schema, exclude: [])
41
41
  self.list_tables(schema, exclude: exclude).each { |table|
42
- conn.exec "drop table if exists #{schema}.#{table} cascade"
42
+ conn.execute "drop table if exists #{schema}.#{table} cascade"
43
43
  }
44
44
  self.list_views(schema, exclude: exclude).each { |view|
45
- conn.exec "drop view if exists #{schema}.#{view} cascade"
45
+ conn.execute "drop view if exists #{schema}.#{view} cascade"
46
46
  }
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ module PgConn
50
50
  def clean!(schema, exclude: [])
51
51
  conn.session.triggers(false) {
52
52
  self.list_tables(schema, exclude: exclude).each { |table|
53
- conn.exec "delete from #{schema}.#{table}"
53
+ conn.execute "delete from #{schema}.#{table}"
54
54
  }
55
55
  }
56
56
  end
@@ -157,9 +157,9 @@ module PgConn
157
157
  uid = "#{schema}.#{table}"
158
158
  seq = sequence(schema, table) or raise ArgumentError, "Table #{uid} does not have a sequence"
159
159
  if value
160
- conn.exec "select setval('#{seq}', #{value})"
160
+ conn.execute "select setval('#{seq}', #{value})"
161
161
  else
162
- conn.exec "select setval('#{seq}', 1, false)"
162
+ conn.execute "select setval('#{seq}', 1, false)"
163
163
  end
164
164
  end
165
165
 
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.41.1"
2
+ VERSION = "0.42.1"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -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
 
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.1
4
+ version: 0.42.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen