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 +4 -4
- data/lib/pg_conn/role_methods.rb +4 -5
- data/lib/pg_conn/schema_methods.rb +4 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 589bec28c740660ad6dd0f09101eda54af26aad2f03a43a27ed7ffa6e422fdf3
|
4
|
+
data.tar.gz: 17ccef8e37a0699331e7c518d1a856652750719dbd2c1a3d04af5173f0d625f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c48594e61dc7caef44a22de75165f5815e69b4dc2e1b181b024291b5bb7cd3ec9eee97aced702a459424afcc093406af9e6d6cb631b128e8117f0084249ac4
|
7
|
+
data.tar.gz: d485db7de8dd27c0eb81db8c1d6940f02ba822a88514e6d13999747c55e902121306e1a0c04105be8881dd0f84819f73aa46101432004b22745e2e9848b0d3d6
|
data/lib/pg_conn/role_methods.rb
CHANGED
@@ -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 ? "
|
48
|
-
create_database_decl = create_database ? "
|
49
|
-
can_login_decl = can_login ? "
|
50
|
-
create_role_decl = create_role ? "
|
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
|
data/lib/pg_conn/version.rb
CHANGED
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
|
-
|
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
|
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
|
+
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-
|
11
|
+
date: 2022-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|