pg_conn 0.10.0 → 0.11.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/TODO +17 -0
  3. data/lib/pg_conn/version.rb +1 -1
  4. data/lib/pg_conn.rb +36 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7708b08a6ef0fcc12d0241ef9a084fe8adcfee342e03933f0f48ec313b9c48b5
4
- data.tar.gz: 716d8e6de64dacab36db01303a47480e0d603a31a8fd24025441ca3a5c8adc2e
3
+ metadata.gz: 634f61e3bd96889ad4207509c73c8b3e6a78c836db9aecbfc974ec5e206c84da
4
+ data.tar.gz: ded665cb58df11f269d951ee0d4cf176c0b99d24c6439edba96f9cf3b03508f0
5
5
  SHA512:
6
- metadata.gz: 12f8f90e3853a0882f93bccde0ea1ce564068612d5d876d26c159625eea4b541bd391b81fe10cbda24b96458129e7caf3c52fe0471d81efc210c151708224887
7
- data.tar.gz: 5fd5a73696fbb9daa9dbc873daee9cf580974ab17bca8fc62743967160f2757e5aaafbb8ece7f8d8e32d122e5d0b3e7b6848a834b5bc16ee65099975ff7337dc
6
+ metadata.gz: 3ad32ff6b5f33b2ec0cd2e309e243177ba1b9b3b5d24281b8e1e2aa8c956f193df64babe15691c80f50807ff7a5dd7c58c966de872b39695354f3aefaaf89343
7
+ data.tar.gz: 6bba6d97558b0c7750971dbc23a3d1eacf1c83072c4fcad3d327324e5547d0607b4f427810bfda3fb0e4d27b3e5f679c437fd5a57572309b9156bfc6d313daef
data/TODO CHANGED
@@ -1,4 +1,20 @@
1
1
  TODO
2
+ o Create aliases
3
+
4
+ tuple -> array
5
+ tuples arrays
6
+ field
7
+ fields # aka. 'column'
8
+ record hash
9
+ records hashes
10
+ struct # exists
11
+ structs
12
+
13
+
14
+ o Make rdbms, role, schema, and session methods part of a PgModel file that
15
+ monkey patch PgConn objects to include a #model method that returns the
16
+ top-level rdbms object
17
+
2
18
  o #group method
3
19
 
4
20
  group(query, column: nil)
@@ -59,6 +75,7 @@ TODO
59
75
  o Allow a :type argument to all query methods that can be used to specify the
60
76
  composition of anonymous record types
61
77
 
78
+ + Quote methods (value, identier, ... -> Postgres string)
62
79
 
63
80
  REFACTOR
64
81
  #!/usr/bin/env ruby
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -226,12 +226,40 @@ module PgConn
226
226
  end
227
227
  end
228
228
 
229
+ # Quote value as an identifier. Value should be a non-nil string
230
+ def quote_identifier(s) = @pg_connection.escape_identifier(s)
231
+
232
+ # Quote the value as a string. Emit 'null' if value is nil
233
+ #
234
+ # The value can be of any type but is converted to a string using #to_s
235
+ # before quoting. This works by default for the regular types Integer,
236
+ # true/false, Time/Date/DateTime, and arrays. Other types may require
237
+ # special handling
238
+ def quote_literal(value)
239
+ case value
240
+ when String; @pg_connection.escape_literal(value)
241
+ when Integer, Float; value.to_s
242
+ when true, false; value.to_s
243
+ when nil; 'null'
244
+ when Date, DateTime; "'#{value}'"
245
+ when Time; "'#{value.strftime("%FT%T%:z")}'"
246
+ when Array; "array[#{value.map { |elem| quote_literal(elem) }.join(', ')}]"
247
+ else
248
+ @pg_connection.escape_literal(value.to_s)
249
+ end
250
+ end
251
+
252
+ def quote_array(value)
253
+
254
+ end
255
+
229
256
  # :call-seq:
230
257
  # exist?(query)
231
258
  # exist?(table, id)
232
259
  # eists?(table, where_clause)
233
260
  #
234
- # Return true iff the query returns exactly one value
261
+ # Return true iff the query returns exactly one value. Use '!empty?' to
262
+ # check if the query returns one or more records
235
263
  def exist?(*args)
236
264
  arg1, arg2 = *args
237
265
  query =
@@ -273,8 +301,9 @@ module PgConn
273
301
 
274
302
  # Return a single value. It is an error if the query doesn't return a
275
303
  # single record with a single column. If :transaction is true, the query
276
- # will be executed in a transaction and be committed it :commit is true
277
- # (the default). This can be used in 'insert ... returning ...' statements
304
+ # will be executed in a transaction and also be committed if :commit is
305
+ # true (this is the default). It can be used to execute 'insert' statements
306
+ # with a 'returning' clause
278
307
  def value(query) #, transaction: false, commit: true)
279
308
  r = pg_exec(query)
280
309
  check_1c(r)
@@ -421,8 +450,11 @@ module PgConn
421
450
  h
422
451
  end
423
452
 
453
+ # TODO: #group - same as table but partitions a table on the given keys
454
+ # returning a map from key to array of records
455
+
424
456
  # TODO: An #array method that returns a map from id to tuple. Hmm... almost
425
- # the same as #map
457
+ # the same as #map
426
458
 
427
459
  # Return a hash from the record id column to an OpenStruct representation
428
460
  # of the record. If the :key_column option is defined it will be used
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.10.0
4
+ version: 0.11.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-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg