pg_conn 0.19.0 → 0.20.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/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +37 -9
- 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: bfe715a08cebb48bb84da6b467a54258e05a774cabfcf7dc0b5492a4059b9f6f
|
4
|
+
data.tar.gz: 26753d7a87a7a6bb7cb91e9e88ed06e08161e9893f739311bae34cbbba9faffc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54dc14b754e355a2e71a3c23a00b89c334afe33c721334f08ce937f285978719541605ef972a4b55a7fbdbd2fd498f5cd1ce39535704b2385b112568a5c6b4b
|
7
|
+
data.tar.gz: 89bdf2c5d23f3f0f8ce4d0973f982a998523ea9b1c496dff20ccd995c6f19abc1faa9e789dbec07b14b29ba6af5e06af4bd2689e106a59cdf75475caba8dbb44
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -64,9 +64,13 @@ module PgConn
|
|
64
64
|
attr_reader :session
|
65
65
|
|
66
66
|
# The transaction timestamp of the most recent SQL statement executed by
|
67
|
-
# #exec or #transaction block
|
67
|
+
# #exec or #transaction block. The timestamp is without time zone
|
68
68
|
attr_reader :timestamp
|
69
69
|
|
70
|
+
# The transaction timestamp of the most recent SQL statement executed by
|
71
|
+
# #exec or #transaction block. The timestamp includes the current time zone
|
72
|
+
attr_reader :timestamptz
|
73
|
+
|
70
74
|
# PG::Error object of the first failed statement in the transaction;
|
71
75
|
# otherwise nil. It is cleared at the beginning of a transaction so be sure
|
72
76
|
# to save it before you run any cleanup code that may initiate new
|
@@ -139,6 +143,7 @@ module PgConn
|
|
139
143
|
if args.last.is_a?(Hash)
|
140
144
|
@field_name_class = args.last.delete(:field_name_class) || Symbol
|
141
145
|
@timestamp = args.last.delete(:timestamp)
|
146
|
+
@timestamptz = args.last.delete(:timestamptz)
|
142
147
|
args.pop if args.last.empty?
|
143
148
|
else
|
144
149
|
@field_name_class = Symbol
|
@@ -212,7 +217,6 @@ module PgConn
|
|
212
217
|
@role = RoleMethods.new(self)
|
213
218
|
@rdbms = RdbmsMethods.new(self)
|
214
219
|
@session = SessionMethods.new(self)
|
215
|
-
@timestamp = nil
|
216
220
|
@savepoints = nil # Stack of savepoint names. Nil if no transaction in progress
|
217
221
|
end
|
218
222
|
|
@@ -238,7 +242,7 @@ module PgConn
|
|
238
242
|
# Quote value as an identifier. Value should be a non-nil string or a symbol
|
239
243
|
def quote_identifier(s)
|
240
244
|
s = s.to_s if s.is_a?(Symbol)
|
241
|
-
|
245
|
+
@pg_connection.escape_identifier(s)
|
242
246
|
end
|
243
247
|
|
244
248
|
# Quote the value as a string. Emit 'null' if value is nil
|
@@ -255,25 +259,36 @@ module PgConn
|
|
255
259
|
when nil; 'null'
|
256
260
|
when Date, DateTime; "'#{value}'"
|
257
261
|
when Time; "'#{value.strftime("%FT%T%:z")}'"
|
258
|
-
when Array; "array[#{value.map { |elem|
|
262
|
+
when Array; "array[#{value.map { |elem| quote_value(elem) }.join(', ')}]"
|
259
263
|
else
|
260
264
|
@pg_connection.escape_literal(value.to_s)
|
261
265
|
end
|
262
266
|
end
|
263
267
|
|
264
|
-
|
265
268
|
# Quote array as a comma-separated sequence of identifiers
|
266
269
|
def quote_identifier_seq(identifiers) = identifiers.map { quote_identifier(_1) }.join(', ')
|
267
270
|
|
268
|
-
# Quote array as a parenthesis-enclosed sequence of identifiers
|
271
|
+
# Quote array as a parenthesis-enclosed sequence of identifiers. TODO: Rename quote_identifier_tuple
|
269
272
|
def quote_identifier_list(identifiers) = "(#{quote_identifier_seq(identifiers)})"
|
270
273
|
|
271
|
-
# Quote array as a
|
274
|
+
# Quote array as a bracket-enclosed sequence of identifiers
|
275
|
+
# def quote_identifier_array(identifiers) = "(#{quote_identifier_seq(identifiers)})"
|
276
|
+
|
277
|
+
# Quote array as a curly-bracket-enclosed sequence of identifiers
|
278
|
+
# def quote_identifier_hash(identifiers) = "(#{quote_identifier_seq(identifiers)})"
|
279
|
+
|
280
|
+
# Quote array as a comma-separated sequence of quoted values
|
272
281
|
def quote_value_seq(values) = values.map { quote_literal(_1) }.join(', ')
|
273
282
|
|
274
|
-
# Quote array as a parenthesis-enclosed list of
|
283
|
+
# Quote array as a parenthesis-enclosed list of quoted values. TODO: Rename to quote_value_tuple
|
275
284
|
def quote_value_list(values) = "(#{quote_value_seq(values)})"
|
276
285
|
|
286
|
+
# Quote array as a bracket-enclosed sequence of values
|
287
|
+
# def quote_identifier_array(values) = "(#{quote_identifier_seq(values)})"
|
288
|
+
|
289
|
+
# Quote array as a curly-bracket-enclosed sequence of values
|
290
|
+
# def quote_identifier_hash(values) = "(#{quote_identifier_seq(values)})"
|
291
|
+
|
277
292
|
# Old aliases. TODO Remove
|
278
293
|
def quote_literal(value) = quote_value(value)
|
279
294
|
def quote_literal_list(values) = quote_value_list(values)
|
@@ -324,6 +339,12 @@ module PgConn
|
|
324
339
|
end
|
325
340
|
end
|
326
341
|
|
342
|
+
# TODO
|
343
|
+
# Query variants
|
344
|
+
# (sql) - simple SQL statement
|
345
|
+
# (schema = nil, table, id-or-where-clause = nil, field-or-fields)
|
346
|
+
#
|
347
|
+
|
327
348
|
# Return a single value. It is an error if the query doesn't return a
|
328
349
|
# single record with a single column. If :transaction is true, the query
|
329
350
|
# will be executed in a transaction and also be committed if :commit is
|
@@ -776,7 +797,14 @@ module PgConn
|
|
776
797
|
@savepoints = []
|
777
798
|
pg_exec("begin")
|
778
799
|
@error = @err = nil
|
779
|
-
|
800
|
+
# FIXME This special-cases the situation where commands are logged to a
|
801
|
+
# file instead of being executed. Maybe remove logging (or execute always
|
802
|
+
# and log as a side-effect)
|
803
|
+
if @pg_connection
|
804
|
+
@timestamp, @timestamptz = @pg_connection.exec(
|
805
|
+
'select current_timestamp, current_timestamp::timestamp without time zone'
|
806
|
+
).tuple_values(0)
|
807
|
+
end
|
780
808
|
end
|
781
809
|
end
|
782
810
|
|
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.20.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-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|