pg_conn 0.3.3 → 0.3.6

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: edc8c2d648a4ea373981633433cfc52ca94cdec159292f052a6ee5a077b56172
4
- data.tar.gz: 7823404356129c95cfcb37869641a32a8982bd11da0d1d7f730893aa0f746701
3
+ metadata.gz: 5f4b26e4c641b161de759efb248c690f9c35fe394006328a065b99a453f99505
4
+ data.tar.gz: 4ec2c0ac1cf0b2dd910688520bde9fda1d9dfdf30ee2d53781caeeb81450fcfb
5
5
  SHA512:
6
- metadata.gz: 6a539ed00e4a16a5ef9d3e400782d42000f19f578382e9721941b82c61cffb3f427856409b978224c42c2b533bb585df5e1c27765c73c1a9071809cc3c734358
7
- data.tar.gz: c93dab2fa0404ffe61b02c4c1fbc0021d290dade58471cd6cabce8e74cbe2372a3b6c1f4a2fefd5eff82ffa4b545b71fb54851fd6f0fcf8abb9b53b16892324a
6
+ metadata.gz: d40cf6491babd1cec85d65c3d658836889fc09a953c02957e435e7cc7013a5320a5adf5da65369f2c3c2d62c50880e6f456c682be1a5c0b34d69d083cd2644d2
7
+ data.tar.gz: b7182f38bd7469eeeaf5ba0c9414bc5b4c195ecf4fa05a6041cd17bb9b05b8e19104d8ebba0e6511b4a7e808ce32593f0b9086f788141f763e753e071e1878f9
@@ -53,7 +53,7 @@ module PgConn
53
53
 
54
54
  # Return true if table exists
55
55
  def exist_table?(schema, table)
56
- conn.exist?(relation_exist_query(schema, table, kind: %w(r)))
56
+ conn.exist?(relation_exist_query(schema, table, kind: %w(r f)))
57
57
  end
58
58
 
59
59
  # Return true if view exists
@@ -73,7 +73,7 @@ module PgConn
73
73
 
74
74
  # Return list of tables in the schema
75
75
  def list_tables(schema)
76
- conn.values relation_list_query(schema, kind: %w(r))
76
+ conn.values relation_list_query(schema, kind: %w(r f))
77
77
  end
78
78
 
79
79
  # Return list of view in the schema
@@ -103,7 +103,7 @@ module PgConn
103
103
 
104
104
  private
105
105
  def relation_exist_query(schema, relation, kind: nil)
106
- kind_sql_list = "'" + (kind.nil? ? %w(r v m) : Array(kind).flatten).join("', '") + "'"
106
+ kind_sql_list = "'" + (kind.nil? ? %w(r f v m) : Array(kind).flatten).join("', '") + "'"
107
107
  %(
108
108
  select 1
109
109
  from pg_class
@@ -114,7 +114,7 @@ module PgConn
114
114
  end
115
115
 
116
116
  def relation_list_query(schema, kind: nil)
117
- kind_sql_list = "'" + (kind.nil? ? %w(r v m) : Array(kind).flatten).join("', '") + "'"
117
+ kind_sql_list = "'" + (kind.nil? ? %w(r f v m) : Array(kind).flatten).join("', '") + "'"
118
118
  %(
119
119
  select relname
120
120
  from pg_class
@@ -157,7 +157,7 @@ module PgConn
157
157
  a.atttypid::regtype::text as "type"
158
158
  from pg_class c
159
159
  join pg_attribute a on a.attrelid = c.oid
160
- where relnamespace::regnamespace::text = 'public'
160
+ where relnamespace::regnamespace::text = '#{schema}'
161
161
  and a.attnum > 0
162
162
  ),
163
163
  relation_clause
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -98,6 +98,7 @@ module PgConn
98
98
  # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
99
99
  # for the full list
100
100
  #
101
+ # TODO: Change to 'initialize(*args, **opts)'
101
102
  def initialize(*args)
102
103
  if args.last.is_a?(Hash)
103
104
  @field_name_class = args.last.delete(:field_name_class) || Symbol
@@ -180,17 +181,17 @@ module PgConn
180
181
  @pg_connection.close if @pg_connection && !@pg_connection.finished?
181
182
  end
182
183
 
183
- def self.new(*args, &block)
184
+ def self.new(*args, **opts, &block)
184
185
  if block_given?
185
186
  begin
186
187
  object = Connection.allocate
187
- object.send(:initialize, *args)
188
+ object.send(:initialize, *args, **opts)
188
189
  yield(object) # if object.pg_connection
189
190
  ensure
190
191
  object.terminate if object.pg_connection
191
192
  end
192
193
  else
193
- super(*args)
194
+ super(*args, **opts)
194
195
  end
195
196
  end
196
197
 
@@ -450,8 +451,7 @@ module PgConn
450
451
  raise ArgumentError, "Unrecognized value: #{arg.inspect}"
451
452
  end
452
453
  }.join(", ")
453
- query = "select * from #{name}(#{args_sql})"
454
- r = pg_exec(query)
454
+ r = pg_exec "select * from #{name}(#{args_sql})"
455
455
  if r.ntuples == 0
456
456
  raise Error, "No records returned"
457
457
  elsif r.ntuples == 1
@@ -477,7 +477,7 @@ module PgConn
477
477
  # fail is false #exec instead return nil but note that postgres doesn't
478
478
  # ignore it so that if you're inside a transaction, the transaction will be
479
479
  # in an error state and if you're also using subtransactions the whole
480
- # transaction stack collapses.
480
+ # transaction stack has collapsed
481
481
  #
482
482
  # TODO: Make sure the transaction stack is emptied on postgres errors
483
483
  def exec(sql, commit: true, fail: true, silent: false)
@@ -636,7 +636,7 @@ module PgConn
636
636
  def pg_exec(arg, fail: true, silent: false)
637
637
  if @pg_connection
638
638
  begin
639
- last_stmt = nil # To make the current SQL statement visible to the rescue clause
639
+ last_stmt = nil # To make the current SQL statement visible to the rescue clause. FIXME Not used?
640
640
  if arg.is_a?(String)
641
641
  return nil if arg == ""
642
642
  last_stmt = arg
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.3.3
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg