pg_conn 0.36.0 → 0.37.0
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 +4 -4
- data/TODO +5 -5
- data/lib/pg_conn/schema_methods.rb +1 -1
- data/lib/pg_conn/session_methods.rb +0 -32
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +45 -4
- 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: 1edd50ec4e7e4f072a695cd044ab6d930dd14cdf763dd335ee0fbb65865e83c4
|
4
|
+
data.tar.gz: 3fe0cf2fe952999dceea4b6776155b7252d4e3f4aeeab7089348fc10ec9cfc5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a84b206b8c7b19813a3acbc63350289e6b072fc1ef8edb65901c99fe6f76fffe3c9ad9ab54d44105652902a8486e5904071e8f6712e73b7b9752019646a8bb8b
|
7
|
+
data.tar.gz: 6725ac8c9ef737db41770df819fefa88cb716ff189d714b139079475ee3255a59ec996e9d9c1e138b971b2b4908d6a91f08b9d7bc3731a7e46c32bd684f28000
|
data/TODO
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
TODO
|
2
|
+
o Drop existing SQL output interface and instead implement a SQL logger
|
3
|
+
|
2
4
|
o Add support for hstore (a hash)
|
3
5
|
|
4
6
|
o Add a <fetch>! method. Require v2
|
5
7
|
value? 0 or 1
|
6
8
|
value 1
|
7
9
|
values 0 or n
|
8
|
-
values? 0 or n
|
9
10
|
values! 1 or more
|
10
11
|
|
11
12
|
o Instrumentation of connection object
|
@@ -43,10 +44,6 @@ TODO
|
|
43
44
|
|
44
45
|
server.call :sp_nic_update_comtext, str_id, str_comtext, site.current_user.id
|
45
46
|
|
46
|
-
o Have a 'with' method that combines multiple brachet-methods:
|
47
|
-
|
48
|
-
conn.with(schema: public, transation: true) { ... }
|
49
|
-
|
50
47
|
o Create aliases
|
51
48
|
tuple -> array
|
52
49
|
tuples arrays
|
@@ -120,6 +117,9 @@ TODO
|
|
120
117
|
composition of anonymous record types
|
121
118
|
|
122
119
|
+ Quote methods (value, identier, ... -> Postgres string)
|
120
|
+
+ Have a 'with' method that combines multiple brachet-methods:
|
121
|
+
conn.with(schema: public, transation: true) { ... }
|
122
|
+
|
123
123
|
|
124
124
|
REFACTOR
|
125
125
|
#!/usr/bin/env ruby
|
@@ -48,7 +48,7 @@ module PgConn
|
|
48
48
|
|
49
49
|
# Empty all tables in the given schema
|
50
50
|
def clean!(schema, exclude: [])
|
51
|
-
conn.
|
51
|
+
conn.without_triggers {
|
52
52
|
self.list_tables(schema, exclude: exclude).each { |table|
|
53
53
|
conn.exec "delete from #{schema}.#{table}"
|
54
54
|
}
|
@@ -84,38 +84,6 @@ module PgConn
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
# Return true if session triggers are enabled. Triggers are enabled by
|
88
|
-
# default by Postgres
|
89
|
-
def triggers?() conn.value "select current_setting('session_replication_role') <> 'replica'" end
|
90
|
-
|
91
|
-
# Enable session triggers
|
92
|
-
def enable_triggers()
|
93
|
-
conn.execute "set session session_replication_role = DEFAULT"
|
94
|
-
end
|
95
|
-
|
96
|
-
# Disable session triggers
|
97
|
-
def disable_triggers()
|
98
|
-
conn.execute "set session session_replication_role = replica"
|
99
|
-
end
|
100
|
-
|
101
|
-
# Execute block with session triggers on or off
|
102
|
-
def triggers(on_off, &block)
|
103
|
-
begin
|
104
|
-
active = triggers?
|
105
|
-
if on_off && !active
|
106
|
-
enable_triggers
|
107
|
-
elsif !on_off && active
|
108
|
-
disable_triggers
|
109
|
-
end
|
110
|
-
yield
|
111
|
-
ensure
|
112
|
-
case active
|
113
|
-
when true; enable_triggers if !triggers?
|
114
|
-
when false; disable_triggers if triggers?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
87
|
private
|
120
88
|
# Like #list but returns the PIDs of the users
|
121
89
|
def pids(database, users)
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -133,7 +133,7 @@ module PgConn
|
|
133
133
|
|
134
134
|
# Name of user
|
135
135
|
def user() @pg_connection.user end
|
136
|
-
alias_method :username, :user # Obsolete FIXME Is it?
|
136
|
+
alias_method :username, :user # Obsolete FIXME Is it? No it is not!
|
137
137
|
|
138
138
|
# Name of database
|
139
139
|
def name() @pg_connection.db end
|
@@ -263,12 +263,13 @@ module PgConn
|
|
263
263
|
# The possible keys of the connection hash are :host, :port, :dbname, :user,
|
264
264
|
# and :password. The connection string can either be a space-separated list
|
265
265
|
# of <key>=<value> pairs with the same keys as the hash, or a URI with the
|
266
|
-
# format 'postgres[ql]://[user[:password]@][host][:port][/name]
|
266
|
+
# format 'postgres[ql]://[user[:password]@][host][:port][/name]. TODO Also
|
267
|
+
# allow :database and :username
|
267
268
|
#
|
268
269
|
# If given an array argument, PgConn will not connect to the database and
|
269
270
|
# instead write its commands to the array. In this case, methods extracting
|
270
271
|
# values from the database (eg. #value) will return nil or raise an
|
271
|
-
# exception
|
272
|
+
# exception. TODO: Remove
|
272
273
|
#
|
273
274
|
# The last variant is used to establish a PgConn from an existing
|
274
275
|
# connection. It doesn't change the connection settings and is not
|
@@ -430,7 +431,8 @@ module PgConn
|
|
430
431
|
end
|
431
432
|
end
|
432
433
|
|
433
|
-
# Mark string argument as already being quoted
|
434
|
+
# Mark string argument as already being quoted. This is done automatically
|
435
|
+
# by all quote_* methods
|
434
436
|
def literal(arg) Literal.new(arg) end
|
435
437
|
|
436
438
|
# Connection member method variations of the PgConn quote class methods
|
@@ -784,6 +786,8 @@ module PgConn
|
|
784
786
|
# There is no variant that takes a single tuple because it would then be
|
785
787
|
# impossible to have array or hash field values
|
786
788
|
def insert(*args, upsert: nil, **opts)
|
789
|
+
# Normalize arguments
|
790
|
+
|
787
791
|
# Add options to args except the special :upsert option
|
788
792
|
args << opts if !opts.empty?
|
789
793
|
|
@@ -1091,6 +1095,43 @@ module PgConn
|
|
1091
1095
|
end
|
1092
1096
|
end
|
1093
1097
|
|
1098
|
+
# Return true if session triggers are enabled. Triggers are enabled by
|
1099
|
+
# default by Postgres
|
1100
|
+
def triggers?() self.value "select current_setting('session_replication_role') <> 'replica'" end
|
1101
|
+
|
1102
|
+
# Enable session triggers
|
1103
|
+
def enable_triggers()
|
1104
|
+
self.execute "set session session_replication_role = DEFAULT"
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
# Disable session triggers
|
1108
|
+
def disable_triggers()
|
1109
|
+
self.execute "set session session_replication_role = replica"
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
# Executes block without triggers
|
1113
|
+
def without_triggers(&block)
|
1114
|
+
triggers(false) { yield }
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
# Execute block with session triggers on or off
|
1118
|
+
def triggers(on_off, &block)
|
1119
|
+
begin
|
1120
|
+
active = triggers?
|
1121
|
+
if on_off && !active
|
1122
|
+
enable_triggers
|
1123
|
+
elsif !on_off && active
|
1124
|
+
disable_triggers
|
1125
|
+
end
|
1126
|
+
yield
|
1127
|
+
ensure
|
1128
|
+
case active
|
1129
|
+
when true; enable_triggers if !triggers?
|
1130
|
+
when false; disable_triggers if triggers?
|
1131
|
+
end
|
1132
|
+
end
|
1133
|
+
end
|
1134
|
+
|
1094
1135
|
def dump(*query)
|
1095
1136
|
records = self.records(*query)
|
1096
1137
|
|
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.37.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: 2025-
|
11
|
+
date: 2025-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|