pg_conn 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47d71f26ef9bedde82dfcaf9c196dfde4bf7e016d8865b195687b717972dc5c9
4
- data.tar.gz: aa0aa1f21ac0a15ae1094bab38ff03b7c9099e08bb5437ed3557a70bf7cc38f4
3
+ metadata.gz: d29017a92f97bb843ada8a10d00ab0a130e0e572e9775f21ddacb9f6d9ca4e66
4
+ data.tar.gz: e56a31694ec01c3ef15ae35b1f5a28304dad179a918c69a687e08fb267f1b30e
5
5
  SHA512:
6
- metadata.gz: d9ca49b277657eb5e7ebd9f5a7896168db39ce12b22d7598eb04b39fd9ee8c183fde92adc2c1e2f506ca532a62fd0fda67ec42660843fd74cddd8f6ea2256f0c
7
- data.tar.gz: '0648150d407460aaf0c5f2f1cb2fdbd6313eed964e72073b2888e4f54cf82af2d96968dd3b7aaa11469620ed459509e948a8fd717ac54284067230702387f0df'
6
+ metadata.gz: a920f75a6d118bdc44e5442adbe38e6ecbc6872ac010f3c29390a25db4e95605541d4bc1dd67a0f7ac1332611119d983211aaff1acda885aca07ed1a464705a7
7
+ data.tar.gz: 4339f922abbdeb6db692a8906a5c5fea4aa21a645be69df90a39473cc2453c9f79c684b8b2e69996a343cc368dcaeaecc960154dbcc78003ec230bd3605363ad
@@ -79,10 +79,9 @@ module PgConn
79
79
  # end
80
80
  end
81
81
 
82
- # List users. TODO Use RE instead of database argument. Also doc this shit
83
- # FIXME: Depends on the <database>__<username> convention
82
+ # List users. TODO Use RE. Also doc this shit
84
83
  def list(database: nil, owner: false, superuser: nil, can_login: nil)
85
- database_clause = database && "rolname like '#{database}\_\_%'"
84
+ database_clause = database && "rolname like '#{database}\\_\\_%'"
86
85
  database_clause = database && "(#{database_clause} or rolname = '#{database}')" if owner
87
86
  superuser_clause = superuser.nil? ? nil : "rolsuper = #{superuser}"
88
87
  can_login_clause = can_login.nil? ? nil : "rolcanlogin = #{can_login}"
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.13.4"
2
+ VERSION = "0.14.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -175,6 +175,9 @@ module PgConn
175
175
  end
176
176
 
177
177
  if @pg_connection && !using_existing_connection
178
+ # Set a dummy notice processor to avoid warnings on stderr
179
+ @pg_connection.set_notice_processor { |message| ; } # Intentionally a nop
180
+
178
181
  # Auto-convert to ruby types
179
182
  type_map = PG::BasicTypeMapForResults.new(@pg_connection)
180
183
 
@@ -677,7 +680,9 @@ module PgConn
677
680
 
678
681
  def rollback() raise Rollback end
679
682
 
680
- # True if a transaction is in progress
683
+ # True if a transaction is in progress. Note that this requires all
684
+ # transactions to be started using PgConn's transaction methods;
685
+ # transactions started using raw SQL are not registered
681
686
  def transaction?() !@savepoints.nil? end
682
687
 
683
688
  # Returns number of transaction or savepoint levels
@@ -715,7 +720,7 @@ module PgConn
715
720
  # invalid and the server is in an invalid state
716
721
  #
717
722
  # It is not an error to call #cancel_transaction when no transaction is in
718
- # progress
723
+ # progress, the method always succeeds
719
724
  def cancel_transaction
720
725
  begin
721
726
  pg_exec("rollback")
@@ -724,25 +729,34 @@ module PgConn
724
729
  @savepoints = nil
725
730
  end
726
731
 
727
- # Execute block within a transaction and return the result of the block.
728
- # The transaction can be rolled back by raising a PgConn::Rollback
729
- # exception in which case #transaction returns nil. Note that the
730
- # transaction timestamp is set to the start of the first transaction even
731
- # if transactions are nested
732
+ # Start a transaction. If called with a block, the block is executed within
733
+ # a transaction that is auto-committed if the commit option is true (the
734
+ # default). #transaction returns the result of the block or nil if no block
735
+ # was given
736
+ #
737
+ # The transaction can be rolled back inside the block by raising a
738
+ # PgConn::Rollback exception in which case #transaction returns nil. Note
739
+ # that the transaction timestamp is set to the start of the first
740
+ # transaction even if transactions are nested
732
741
  def transaction(commit: true, &block)
733
- result = nil
734
- begin
742
+ if block_given?
743
+ result = nil
744
+ begin
745
+ push_transaction
746
+ result = yield
747
+ rescue PgConn::Rollback
748
+ pop_transaction(commit: false)
749
+ return nil
750
+ rescue PG::Error
751
+ @savepoints = nil
752
+ raise
753
+ end
754
+ pop_transaction(commit: commit)
755
+ result
756
+ else
735
757
  push_transaction
736
- result = yield
737
- rescue PgConn::Rollback
738
- pop_transaction(commit: false)
739
- return nil
740
- rescue PG::Error
741
- @savepoints = nil
742
- raise
758
+ nil
743
759
  end
744
- pop_transaction(commit: commit)
745
- result
746
760
  end
747
761
 
748
762
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_conn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-10 00:00:00.000000000 Z
11
+ date: 2024-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg