pg_conn 0.3.4 → 0.3.7

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: 7f16674ecd9e41796dab773ca10d938a61619859676d2f8746a0d6694e598bb2
4
- data.tar.gz: 9b88a48fa7692419c2bbf81e6f1162eb8a54477ac821517e3ba80738923b6128
3
+ metadata.gz: 589bec28c740660ad6dd0f09101eda54af26aad2f03a43a27ed7ffa6e422fdf3
4
+ data.tar.gz: 17ccef8e37a0699331e7c518d1a856652750719dbd2c1a3d04af5173f0d625f5
5
5
  SHA512:
6
- metadata.gz: f31c28e8d255792671cce8e1697cdfbc6d140814cb3956ce2935c24aa4d52f2fffb5945761051568b97f1cbdafa39165dbe581a6d7b7ae0a594af238833acc5b
7
- data.tar.gz: 44bac37de6928e4905db9c53c97728b1c528a17d23c62a8539b44f830e84d6e2b42c270a18028d5648b05aa840c868ddfb57e9affa3aee8023332f8c53f28aab
6
+ metadata.gz: 91c48594e61dc7caef44a22de75165f5815e69b4dc2e1b181b024291b5bb7cd3ec9eee97aced702a459424afcc093406af9e6d6cb631b128e8117f0084249ac4
7
+ data.tar.gz: d485db7de8dd27c0eb81db8c1d6940f02ba822a88514e6d13999747c55e902121306e1a0c04105be8881dd0f84819f73aa46101432004b22745e2e9848b0d3d6
@@ -44,11 +44,10 @@ module PgConn
44
44
  # Create a new role
45
45
  def create(rolename, superuser: false, create_database: false, can_login: false, create_role: false)
46
46
  user_decl = "create role \"#{rolename}\""
47
- superuser_decl = superuser ? "--superuser" : nil
48
- create_database_decl = create_database ? "--createdb" : "--nocreatedb"
49
- can_login_decl = can_login ? "--login" : "--nologin"
50
- create_role_decl = create_role ? "--createrole" : "--nocreaterole"
51
-
47
+ superuser_decl = superuser ? "superuser" : "nosuperuser"
48
+ create_database_decl = create_database ? "createdb" : "nocreatedb"
49
+ can_login_decl = can_login ? "login" : "nologin"
50
+ create_role_decl = create_role ? "createrole" : "nocreaterole"
52
51
  stmt = [user_decl, superuser_decl, can_login_decl, create_role_decl].compact.join(" ")
53
52
  conn.exec stmt
54
53
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.7"
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.4
4
+ version: 0.3.7
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-07 00:00:00.000000000 Z
11
+ date: 2022-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg