pg_conn 0.27.1 → 0.29.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/TODO +8 -5
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +22 -0
- 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: ba42158e0277b532ebcdb7125dd0c963de3c936a4bdb918e1a980fd6aa2674ed
|
4
|
+
data.tar.gz: c371efcf188d9c49b7e005e2cb4f92f72431b6b20e0fbd4766904d8b99743ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d518daefe587aca974092084628505c9c82a8615e4cda9baf3ea3b3526ebdf2e48be1adc0bfe4231f4b617353359c0942f16f6d97c33bc67cc744db0dd7d11f
|
7
|
+
data.tar.gz: b534cc5f4669c84e6248f57aa6abef4678d37405b6008814f74521d9c691cc0cd4b4983795429832f40c9618071248887ba5b3bcb09c2fd05ca21f37126ae696
|
data/TODO
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
TODO
|
2
|
-
o Add a
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
o Add support for hstore (a hash)
|
3
|
+
|
4
|
+
o Add a <fetch>! method. Require v2
|
5
|
+
value? 0 or 1
|
6
|
+
value 1
|
7
|
+
values 0 or n
|
8
|
+
values? 0 or n
|
9
|
+
values! 1 or more
|
7
10
|
|
8
11
|
o Instrumentation of connection object
|
9
12
|
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "pg"
|
2
2
|
require 'ostruct'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
require_relative "pg_conn/version"
|
5
6
|
require_relative "pg_conn/role_methods"
|
@@ -31,6 +32,10 @@ module PgConn
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
# Used to mark strings as literals that should not be quoted. This is the
|
36
|
+
# case for row and record values
|
37
|
+
class Literal < String; end
|
38
|
+
|
34
39
|
# All results from the database are converted into native Ruby types
|
35
40
|
class Connection
|
36
41
|
# Make PgConn::Connection pretend to be an instance of the PgConn module
|
@@ -246,6 +251,8 @@ module PgConn
|
|
246
251
|
end
|
247
252
|
end
|
248
253
|
|
254
|
+
def literal(arg) Literal.new(arg) end
|
255
|
+
|
249
256
|
# Quote argument as an identifier. The argument should be a non-nil string
|
250
257
|
# or a symbol
|
251
258
|
def quote_identifier(s)
|
@@ -263,6 +270,10 @@ module PgConn
|
|
263
270
|
# true/false, Time/Date/DateTime, and arrays. Other types may require
|
264
271
|
# special handling
|
265
272
|
#
|
273
|
+
# Hashes are quoted as a literal JSON expression. The result is a string
|
274
|
+
# and it is the application's responsibility to cast them to either 'json'
|
275
|
+
# or 'jsonb'
|
276
|
+
#
|
266
277
|
# Note that a tuple value (an array) must be quoted using #quote_tuple
|
267
278
|
# because #quote_value would quote the tuple as an array instead of a list
|
268
279
|
# of values
|
@@ -274,6 +285,7 @@ module PgConn
|
|
274
285
|
#
|
275
286
|
def quote_value(value, elem_type: nil)
|
276
287
|
case value
|
288
|
+
when Literal; value
|
277
289
|
when String; @pg_connection.escape_literal(value)
|
278
290
|
when Integer, Float; value.to_s
|
279
291
|
when true, false; value.to_s
|
@@ -287,6 +299,7 @@ module PgConn
|
|
287
299
|
else
|
288
300
|
"array[#{value.map { |elem| quote_value(elem) }.join(', ')}]"
|
289
301
|
end
|
302
|
+
when Hash; value.to_json
|
290
303
|
else
|
291
304
|
@pg_connection.escape_literal(value.to_s)
|
292
305
|
end
|
@@ -339,6 +352,8 @@ module PgConn
|
|
339
352
|
#
|
340
353
|
# Return true iff the query returns exactly one record. Use '!empty?' to
|
341
354
|
# check if the query returns one or more records
|
355
|
+
#
|
356
|
+
# TODO: Rename #present? and use #exists? to query schema objects
|
342
357
|
def exist?(*query)
|
343
358
|
!empty?(*query)
|
344
359
|
end
|
@@ -363,6 +378,13 @@ module PgConn
|
|
363
378
|
value("select count(*) from (#{inner_query}) as inner_query")
|
364
379
|
end
|
365
380
|
|
381
|
+
# TODO (but breaks a lot of code)
|
382
|
+
# value 1
|
383
|
+
# value? 0 or 1
|
384
|
+
#
|
385
|
+
# values 1 or more
|
386
|
+
# values? 0 or more
|
387
|
+
|
366
388
|
# Return a single value. It is an error if the query doesn't return a
|
367
389
|
# single record with a single column.
|
368
390
|
#
|
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.29.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:
|
11
|
+
date: 2025-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|