pg_conn 0.47.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f44c95a305b34572b5be9025a51b3cff362f08aaf3aa434c4e5b91d0676fb058
4
- data.tar.gz: b8ef0db1095940087e8d08113f76cde7f245ca12a5c56fde5dd9863b85527fe6
3
+ metadata.gz: c017287998b7b7c473e0532c44ff8f209d322158c6ef79b97a462270cc1d10ef
4
+ data.tar.gz: 6939299127cda711bf3fd1c0c349737c9f943c026abc13885bb9e699ce6607b0
5
5
  SHA512:
6
- metadata.gz: 80dd909eb3bdb1cdd8100a138c3707dd4a8e23ec975754eb24862464bd8a8013adbd95e455a9b2dd179298740c1bfbbf6b8ad44c33b07e79c95c2c4b81732b41
7
- data.tar.gz: 5224dbafd555d6d05b62f9006aa4a731f9a9e6d434d7c4b8fd39a2a70e99e8ef2db97ef3db3fa5fe3e39c7ecccf032633f134b6845c5e5db58a8077ce9b6a2f2
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
- relation_clause = relation ? "relname = '#{relation}'" : nil
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
- relation_clause
220
+ relation_expr
216
221
  ].compact.join(" and ")
217
222
  end
218
223
 
219
- def column_list_type_query(schema, relation)
220
- relation_clause = relation ? "relname = '#{relation}'" : nil
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
- relation_clause
236
+ column_expr,
237
+ relation_expr
231
238
  ].compact.join(" and ")
232
239
  end
233
240
  end
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.47.0"
2
+ VERSION = "0.49.0"
3
3
  end
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'
@@ -94,6 +98,12 @@ module PgConn
94
98
  Literal.new values.map { |value| quote_value(value, **opts) }.join(", ")
95
99
  end
96
100
 
101
+ # Quote array as a row - '(value, value, ...)'
102
+ def self.quote_row(row, **opts) = quote_list(row, **opts)
103
+
104
+ # Quote values as a list of rows - '(value, value), (value, value), ...'
105
+ def self.quote_rows(rows, **opts) = rows.map { quote_list(_1, **opts) }.join(', ')
106
+
97
107
  # Quote an array of values as a tuple. The element types should be in the
98
108
  # same order as the array arguments. #quote_tuples is same as #quote_values
99
109
  # except the values may have different types (this makes no difference
@@ -113,7 +123,7 @@ module PgConn
113
123
  Literal.new tuples.map { |tuple| "(#{quote_tuple(tuple, **opts)})" }.join(", ")
114
124
  end
115
125
 
116
- # Quote array elements as a comma separated list of values and enclosed en
126
+ # Quote array elements as a comma separated list of values and enclosed in
117
127
  # parenthesis. Eg. [1, 2] => "(1, 2)"
118
128
  def self.quote_list(array, **opts) = quote_tuples([array], **opts)
119
129
 
@@ -471,6 +481,8 @@ module PgConn
471
481
  def quote_identifiers(idents) = PgConn.quote_identifiers(idents)
472
482
  def quote_value(value, **opts) = PgConn.quote_value(value, json_type: self.default_json_type, **opts)
473
483
  def quote_values(values, **opts) = PgConn.quote_values(values, json_type: self.default_json_type, **opts)
484
+ def quote_row(row, **opts) = PgConn.quote_row(row, json_type: self.default_json_type, **opts)
485
+ def quote_rows(rows, **opts) = PgConn.quote_rows(rows, json_type: self.default_json_type, **opts)
474
486
  def quote_tuple(tuple, **opts) = PgConn.quote_tuple(tuple, json_type: self.default_json_type, **opts)
475
487
  def quote_tuples(tuples, **opts) = PgConn.quote_tuples(tuples, json_type: self.default_json_type, **opts)
476
488
 
@@ -645,7 +657,7 @@ module PgConn
645
657
 
646
658
  # Return a hash from column name (a Symbol) to field value. It is an error if
647
659
  # the query returns more than one record. It blows up if a column name is
648
- # not a valid ruby symbol
660
+ # not a valid ruby symbol (eg. contains blanks)
649
661
  def record(*query)
650
662
  r = pg_exec(parse_query *query)
651
663
  check_1r(r)
@@ -755,7 +767,7 @@ module PgConn
755
767
  r.each_row { |row|
756
768
  key_value = row.delete_at(key_index)
757
769
  key_value = key_value.to_sym if symbol
758
- !h.key?(key_value) or raise Error, "Duplicate key: #{key_value}"
770
+ !h.key?(key_value) or raise Error, "Duplicate key: #{key_value.inspect}"
759
771
  h[key_value] = (one ? row.first : row)
760
772
  }
761
773
  h
@@ -846,7 +858,7 @@ module PgConn
846
858
  # TODO
847
859
  # insert(table, [fields], field-name-map, object|objects)
848
860
  # field-name-map:
849
- # { database-column-name: object-method-name } # calls method on orbejt
861
+ # { database-column-name: object-method-name } # calls method on object
850
862
  #
851
863
  def insert(*args, upsert: nil, **opts)
852
864
  # Normalize arguments
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_conn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.47.0
4
+ version: 0.49.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen