pg_conn 0.7.3 → 0.8.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: 208fa123e91d3d1020b3c9030ab513bc482dbb5f42803e6c8f5500fa0f020f1f
4
- data.tar.gz: f16371469c57bf3a812643dc537ca8e214f5cef30a40bde1f6517dd99f4edaca
3
+ metadata.gz: 599ccb65823ae32d0a3baf96ba0d636104c7994f2473d71eafa1927228f47302
4
+ data.tar.gz: b08bb15804c363fb25c03e102f35de6f64694220b9865e5a9d0525516cc6db24
5
5
  SHA512:
6
- metadata.gz: eafa6801dd0b4e6a1c5ea08df77188453c87478086e898a9fa6ddd9cbf15a742dc14ba939c25f63b5742ca98f07c79ffca429fa37ebbaab4448026c7927bb701
7
- data.tar.gz: a433659b74b05ed68fc916dc0bf11c78a53471b865b7f9fab6646241e2c9f525d9c272142cc8121634080a5cc921aacbf22f699c8b451b2c597f22a991a2ce2e
6
+ metadata.gz: 1dba080845fa70f52f4b0614392be42169822809a6a436da49f3c8a2453614c5b9586927ee5abfa5546933d43370d691458fb0677b350a0c40d1257acd42b79b
7
+ data.tar.gz: 8cd9e0b2481ba760dd250a7e68bda460ddf38564843929143ca3622904484866818b75bad0bc9c8a9fbbacd8bd9980eaa53b8670f4e68d9f0f04886fe24f573c
@@ -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
- conn.exec "drop owned by #{rolenames_sql} cascade" if cascade
68
- conn.exec "drop role #{rolenames_sql}"
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
 
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.7.3"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -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. #pg_exec returns a PG::Result object or nil if +arg+ was empty.
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.7.3
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-01-21 00:00:00.000000000 Z
11
+ date: 2024-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg