pg_conn 0.7.2 → 0.8.0
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 +10 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +16 -2
- 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: 599ccb65823ae32d0a3baf96ba0d636104c7994f2473d71eafa1927228f47302
|
4
|
+
data.tar.gz: b08bb15804c363fb25c03e102f35de6f64694220b9865e5a9d0525516cc6db24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dba080845fa70f52f4b0614392be42169822809a6a436da49f3c8a2453614c5b9586927ee5abfa5546933d43370d691458fb0677b350a0c40d1257acd42b79b
|
7
|
+
data.tar.gz: 8cd9e0b2481ba760dd250a7e68bda460ddf38564843929143ca3622904484866818b75bad0bc9c8a9fbbacd8bd9980eaa53b8670f4e68d9f0f04886fe24f573c
|
data/lib/pg_conn/role_methods.rb
CHANGED
@@ -52,7 +52,7 @@ module PgConn
|
|
52
52
|
conn.exec stmt
|
53
53
|
end
|
54
54
|
|
55
|
-
# Remove all privileges from the given role
|
55
|
+
# Remove all privileges from the given role. TODO #demote!, strip! ?
|
56
56
|
def clean(rolename)
|
57
57
|
end
|
58
58
|
|
@@ -60,12 +60,18 @@ module PgConn
|
|
60
60
|
# privileges and objects too if :cascade is true. Note that cascade only
|
61
61
|
# works if connected to the database where the privileges exist. The
|
62
62
|
# :silent option is used in tests - fix it somehow!
|
63
|
-
def drop(*rolenames, cascade: false, silent: false)
|
63
|
+
def drop(*rolenames, cascade: false, fail: true, silent: false)
|
64
64
|
rolenames = Array(rolenames).flatten.compact.select { |role| exist?(role) }
|
65
65
|
return false if rolenames.empty?
|
66
66
|
rolenames_sql = PgConn.sql_idents(rolenames)
|
67
|
-
|
68
|
-
|
67
|
+
begin
|
68
|
+
conn.exec("drop owned by #{rolenames_sql} cascade", fail: false, silent: silent) if cascade
|
69
|
+
conn.exec("drop role #{rolenames_sql}", fail: fail, silent: silent)
|
70
|
+
rescue PG::Error
|
71
|
+
raise if fail
|
72
|
+
conn.cancel_transaction
|
73
|
+
return false
|
74
|
+
end
|
69
75
|
true
|
70
76
|
end
|
71
77
|
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -70,7 +70,7 @@ module PgConn
|
|
70
70
|
# element defaults to nil if not found
|
71
71
|
def err
|
72
72
|
@err ||=
|
73
|
-
if error&.message =~ /.*?ERROR:\s*(.*?)\n(?:.*?(\s*LINE\s+(\d+)
|
73
|
+
if error&.message =~ /.*?ERROR:\s*(.*?)\n(?:.*?(\s*LINE\s+(\d+): ).*?\n(?:(\s+)\^\n)?)?/
|
74
74
|
[$1.capitalize, $3&.to_i, $4 && ($4.size - $2.size + 1)]
|
75
75
|
else
|
76
76
|
[nil, nil, nil]
|
@@ -520,6 +520,19 @@ module PgConn
|
|
520
520
|
transaction(commit: commit) { execute(sql, fail: fail, silent: silent) }
|
521
521
|
end
|
522
522
|
|
523
|
+
# Like #exec but returns true/false depending on if the command succeeded.
|
524
|
+
# There is not corresponding #exeucte? method because any failure rolls
|
525
|
+
# back the whole transaction stack. TODO: Check which exceptions that
|
526
|
+
# should be captured
|
527
|
+
def exec?(sql, commit: true, silent: true)
|
528
|
+
begin
|
529
|
+
exec(sql, commit: commit, fail: true, silent: silent)
|
530
|
+
rescue PG::Error
|
531
|
+
return false
|
532
|
+
end
|
533
|
+
return true
|
534
|
+
end
|
535
|
+
|
523
536
|
# Execute SQL statement(s) without a transaction block and return the
|
524
537
|
# number of affected records (if any). This used to call procedures that
|
525
538
|
# may manipulate transactions. The +sql+ argument can be a SQL command or
|
@@ -660,7 +673,7 @@ module PgConn
|
|
660
673
|
#
|
661
674
|
# Execute statement(s) on the server. If the argument is an array of
|
662
675
|
# commands, the commands are concatenated with ';' before being sent to the
|
663
|
-
# server.
|
676
|
+
# server. #pg_exec returns a PG::Result object or nil if +arg+ was empty.
|
664
677
|
# #exec pass Postgres exceptions to the caller unless :fail is false
|
665
678
|
#
|
666
679
|
# FIXME: Error message prints the last statement but what if another
|
@@ -683,6 +696,7 @@ module PgConn
|
|
683
696
|
else
|
684
697
|
stmts = arg.flatten.compact
|
685
698
|
return nil if stmts.empty?
|
699
|
+
# stmts.unshift("set on_error_exit stop")
|
686
700
|
last_stmt = stmts.last
|
687
701
|
@pg_connection.exec(stmts.join(";\n"))
|
688
702
|
end
|
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.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2024-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|