pg_conn 0.35.1 → 0.36.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 +33 -35
- 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: 3d6940809a3f62bfad5cd2a94566a76bcd1944ad5b6ded6df2be159a010b2169
|
4
|
+
data.tar.gz: 6f213cb288ba5a85205fd5054fb498e6200b0319eee8c2bbc8c60515705410f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90dab6c75eb2cfd7a99b39676a4aa0dc167462e37e9229d96ed30517b4ff0c691f6b4389ceb6d26c3f2562d7ce4e7dd2be17d054f1e61369989fb9f8c3db8e1
|
7
|
+
data.tar.gz: f91893227ef9697eb236051728d509727b2d20b5d9efd7c6f848cf2e887b1abc0e5c8a48da291914372049ab25aee6580b9b74fd422d269c3e7813928032dd23
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -40,13 +40,13 @@ module PgConn
|
|
40
40
|
#
|
41
41
|
def self.quote_identifier(s)
|
42
42
|
s = s.to_s if s.is_a?(Symbol)
|
43
|
-
escape_identifier(s).gsub(/\./, '"."').sub(/"\*"/, "*")
|
43
|
+
Literal.new escape_identifier(s).gsub(/\./, '"."').sub(/"\*"/, "*")
|
44
44
|
end
|
45
45
|
|
46
46
|
# Quote identifiers and concatenate them using ',' as separator
|
47
|
-
def self.quote_identifiers(idents) = idents.map { |ident| quote_identifier(ident) }.join(", ")
|
47
|
+
def self.quote_identifiers(idents) = Literal.new idents.map { |ident| quote_identifier(ident) }.join(", ")
|
48
48
|
|
49
|
-
# Quote the value as a string.
|
49
|
+
# Quote the value as a string. Returns a Literal object
|
50
50
|
#
|
51
51
|
# The value can be of any type but is converted to a string using #to_s
|
52
52
|
# before quoting. This works by default for the regular types Integer,
|
@@ -55,7 +55,7 @@ module PgConn
|
|
55
55
|
#
|
56
56
|
# Hashes are quoted as a literal JSON expression converted into the given
|
57
57
|
# :json_type. If :json_type is nil, it is the application's responsibility to
|
58
|
-
# cast
|
58
|
+
# cast the value to either 'json' or 'jsonb'
|
59
59
|
#
|
60
60
|
# Note that a tuple value (an array) must be quoted using #quote_tuple
|
61
61
|
# because #quote_value would quote the tuple as an array value instead of a
|
@@ -67,30 +67,31 @@ module PgConn
|
|
67
67
|
# is guaranteed to be non-empty. Nested arrays are not supported
|
68
68
|
#
|
69
69
|
def self.quote_value(value, elem_type: nil, json_type: nil)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
Literal.new \
|
71
|
+
case value
|
72
|
+
when Literal; value
|
73
|
+
when String; escape_literal(value)
|
74
|
+
when Integer, Float; value.to_s
|
75
|
+
when true, false; value.to_s
|
76
|
+
when nil; 'null'
|
77
|
+
when Date, DateTime; "'#{value}'"
|
78
|
+
when Time; "'#{value.strftime("%FT%T%:z")}'"
|
79
|
+
when Array
|
80
|
+
if value.empty?
|
81
|
+
elem_type or raise Error, "Empty array without elem_type"
|
82
|
+
"array[]::#{elem_type}[]"
|
83
|
+
else
|
84
|
+
"array[#{value.map { |elem| quote_value(elem) }.join(', ')}]"
|
85
|
+
end
|
86
|
+
when Hash; ["'#{value.to_json}'", json_type].compact.join('::')
|
82
87
|
else
|
83
|
-
|
88
|
+
escape_literal(value.to_s)
|
84
89
|
end
|
85
|
-
when Hash; ["'#{value.to_json}'", json_type].compact.join('::')
|
86
|
-
else
|
87
|
-
escape_literal(value.to_s)
|
88
|
-
end
|
89
90
|
end
|
90
91
|
|
91
92
|
# Quote values and concatenate them using ',' as separator
|
92
93
|
def self.quote_values(values, **opts)
|
93
|
-
values.map { |value| quote_value(value, **opts) }.join(", ")
|
94
|
+
Literal.new values.map { |value| quote_value(value, **opts) }.join(", ")
|
94
95
|
end
|
95
96
|
|
96
97
|
# Quote an array of values as a tuple. The element types should be in the
|
@@ -101,7 +102,7 @@ module PgConn
|
|
101
102
|
# Note that it is :elem_types (plural) and not :elem_type
|
102
103
|
def self.quote_tuple(tuple, elem_types: nil, **opts)
|
103
104
|
elem_types = Array(elem_types)
|
104
|
-
tuple.map { |value|
|
105
|
+
Literal.new tuple.map { |value|
|
105
106
|
elem_type = value.is_a?(Array) ? elem_types&.shift : nil
|
106
107
|
quote_value(value, **opts, elem_type: elem_type)
|
107
108
|
}.join(", ")
|
@@ -109,7 +110,7 @@ module PgConn
|
|
109
110
|
|
110
111
|
# Quote an array of tuples
|
111
112
|
def self.quote_tuples(tuples, **opts)
|
112
|
-
tuples.map { |tuple| "(#{quote_tuple(tuple, **opts)})" }.join(", ")
|
113
|
+
Literal.new tuples.map { |tuple| "(#{quote_tuple(tuple, **opts)})" }.join(", ")
|
113
114
|
end
|
114
115
|
|
115
116
|
# Used to mark strings as literals that should not be quoted. This is the
|
@@ -429,8 +430,7 @@ module PgConn
|
|
429
430
|
end
|
430
431
|
end
|
431
432
|
|
432
|
-
# Mark argument as already being quoted
|
433
|
-
# quote methods
|
433
|
+
# Mark string argument as already being quoted
|
434
434
|
def literal(arg) Literal.new(arg) end
|
435
435
|
|
436
436
|
# Connection member method variations of the PgConn quote class methods
|
@@ -1155,17 +1155,16 @@ module PgConn
|
|
1155
1155
|
end
|
1156
1156
|
|
1157
1157
|
# Common implementation for #quote_record and #quote_records that avoids
|
1158
|
-
# querying the database multiple times or duplication the code
|
1159
|
-
# flag is true when called via #quote_records
|
1158
|
+
# querying the database multiple times or duplication the code
|
1160
1159
|
#
|
1161
1160
|
# @data can be a Hash, Array, or OpenStruct. Hash keys must be symbols or
|
1162
1161
|
# strings, they belong to the same namespace so :k and "k" refer to the
|
1163
|
-
# same value
|
1162
|
+
# same value. The :array flag is true when called via #quote_records
|
1164
1163
|
#
|
1165
1164
|
# Note that #quote_record_impl queries the database for information about
|
1166
1165
|
# the type. TODO Cache this information?
|
1167
|
-
|
1168
|
-
|
1166
|
+
#
|
1167
|
+
def quote_record_impl(datas, schema_name = nil, type, elem_types: nil, array: nil, **opts)
|
1169
1168
|
datas = [datas] if !array
|
1170
1169
|
|
1171
1170
|
pg_type = [schema_name, type].compact.join('.')
|
@@ -1192,10 +1191,9 @@ module PgConn
|
|
1192
1191
|
}
|
1193
1192
|
|
1194
1193
|
if array
|
1195
|
-
|
1196
|
-
"array[#{literals.join(', ')}]::#{pg_type}[]"
|
1194
|
+
Literal.new "array[#{literals.join(', ')}]::#{pg_type}[]"
|
1197
1195
|
else
|
1198
|
-
literals.first
|
1196
|
+
Literal.new literals.first
|
1199
1197
|
end
|
1200
1198
|
end
|
1201
1199
|
|
@@ -1235,7 +1233,7 @@ module PgConn
|
|
1235
1233
|
end
|
1236
1234
|
|
1237
1235
|
STDOUT_PRODUCER = lambda { |msg| $stdout.puts msg }
|
1238
|
-
STDERR_PRODUCER = lambda { |msg| $stderr.puts msg }
|
1236
|
+
STDERR_PRODUCER = lambda { |msg| $stderr.puts msg; $stderr.flush }
|
1239
1237
|
ERROR_PRODUCER = lambda { |msg, stmt| $stderr.puts stmt, nil, msg; $stderr.flush }
|
1240
1238
|
|
1241
1239
|
# Map from message level to default producer. Note that we rely on the key
|
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.36.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-03-
|
11
|
+
date: 2025-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|