pg_conn 0.48.0 → 0.49.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/schema_methods.rb +12 -5
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +7 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c017287998b7b7c473e0532c44ff8f209d322158c6ef79b97a462270cc1d10ef
|
|
4
|
+
data.tar.gz: 6939299127cda711bf3fd1c0c349737c9f943c026abc13885bb9e699ce6607b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01d12b622790f3310a94d1c5191d811a9fb481d488b55f6e00018fe704ec6a9916b67ad5998c15977bc21d29792be96b82f81bcfc90c06100f7af2b1df967d71
|
|
7
|
+
data.tar.gz: 80e0c6c6e7825c949c5f23d3c98e8bc49ddf0653bba13bf666b0816d0e2656b788ea37af52d9009914a961cb197035dbd4643a9ad65fd9c9ccf76b9c46088f63
|
|
@@ -116,6 +116,11 @@ module PgConn
|
|
|
116
116
|
conn.tuples column_list_type_query(schema, relation)
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
# Return type of the given column or nil if not found
|
|
120
|
+
def list_column_type(schema, relation = nil, column)
|
|
121
|
+
conn.tuples(column_list_type_query(schema, relation, column)).first&.last
|
|
122
|
+
end
|
|
123
|
+
|
|
119
124
|
def exist_function(schema, function, signature)
|
|
120
125
|
raise NotImplementedError
|
|
121
126
|
end
|
|
@@ -203,7 +208,7 @@ module PgConn
|
|
|
203
208
|
end
|
|
204
209
|
|
|
205
210
|
def column_list_query(schema, relation)
|
|
206
|
-
|
|
211
|
+
relation_expr = relation ? "relname = '#{relation}'" : nil
|
|
207
212
|
[
|
|
208
213
|
%(
|
|
209
214
|
select '#{schema}' || '.' || c.relname || '.' || a.attname
|
|
@@ -212,12 +217,13 @@ module PgConn
|
|
|
212
217
|
where relnamespace::regnamespace::text = '#{schema}'
|
|
213
218
|
and a.attnum > 0
|
|
214
219
|
),
|
|
215
|
-
|
|
220
|
+
relation_expr
|
|
216
221
|
].compact.join(" and ")
|
|
217
222
|
end
|
|
218
223
|
|
|
219
|
-
def column_list_type_query(schema, relation)
|
|
220
|
-
|
|
224
|
+
def column_list_type_query(schema, relation, column = nil)
|
|
225
|
+
column_expr = column && "a.attname = '#{column}'"
|
|
226
|
+
relation_expr = relation ? "relname = '#{relation}'" : nil
|
|
221
227
|
[
|
|
222
228
|
%(
|
|
223
229
|
select '#{schema}' || '.' || c.relname || '.' || a.attname as "column",
|
|
@@ -227,7 +233,8 @@ module PgConn
|
|
|
227
233
|
where relnamespace::regnamespace::text = '#{schema}'
|
|
228
234
|
and a.attnum > 0
|
|
229
235
|
),
|
|
230
|
-
|
|
236
|
+
column_expr,
|
|
237
|
+
relation_expr
|
|
231
238
|
].compact.join(" and ")
|
|
232
239
|
end
|
|
233
240
|
end
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
|
@@ -53,6 +53,10 @@ module PgConn
|
|
|
53
53
|
# true/false, Time/Date/DateTime, and arrays. Other types may require
|
|
54
54
|
# special handling
|
|
55
55
|
#
|
|
56
|
+
# Arrays are quoted using the Array constructor (Array[...]) so the quoted
|
|
57
|
+
# string can't be used in 'VALUE in (LIST)' constructs, use #quote_values
|
|
58
|
+
# instead
|
|
59
|
+
#
|
|
56
60
|
# Hashes are quoted as a literal JSON expression converted into the given
|
|
57
61
|
# :json_type. If :json_type is nil, it is the application's responsibility to
|
|
58
62
|
# cast the value to either 'json' or 'jsonb'
|
|
@@ -653,7 +657,7 @@ module PgConn
|
|
|
653
657
|
|
|
654
658
|
# Return a hash from column name (a Symbol) to field value. It is an error if
|
|
655
659
|
# the query returns more than one record. It blows up if a column name is
|
|
656
|
-
# not a valid ruby symbol
|
|
660
|
+
# not a valid ruby symbol (eg. contains blanks)
|
|
657
661
|
def record(*query)
|
|
658
662
|
r = pg_exec(parse_query *query)
|
|
659
663
|
check_1r(r)
|
|
@@ -763,7 +767,7 @@ module PgConn
|
|
|
763
767
|
r.each_row { |row|
|
|
764
768
|
key_value = row.delete_at(key_index)
|
|
765
769
|
key_value = key_value.to_sym if symbol
|
|
766
|
-
!h.key?(key_value) or raise Error, "Duplicate key: #{key_value}"
|
|
770
|
+
!h.key?(key_value) or raise Error, "Duplicate key: #{key_value.inspect}"
|
|
767
771
|
h[key_value] = (one ? row.first : row)
|
|
768
772
|
}
|
|
769
773
|
h
|
|
@@ -854,7 +858,7 @@ module PgConn
|
|
|
854
858
|
# TODO
|
|
855
859
|
# insert(table, [fields], field-name-map, object|objects)
|
|
856
860
|
# field-name-map:
|
|
857
|
-
# { database-column-name: object-method-name } # calls method on
|
|
861
|
+
# { database-column-name: object-method-name } # calls method on object
|
|
858
862
|
#
|
|
859
863
|
def insert(*args, upsert: nil, **opts)
|
|
860
864
|
# Normalize arguments
|