pg_conn 0.10.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO +17 -0
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +38 -4
- 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: '006583d902e2254d449d5275be8e91412f2d272ae6ce8de927a1f0bec87e1f05'
|
4
|
+
data.tar.gz: 4a983af740d9032ff6856fffea989510d3c00452dea075312b1c2c9c9857eaef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ba88b850bb8abd1d0073b4be090033d1fbaabd51177f62476c511ab8dbf73867e657bd1daf8952d784253adb2d168109dba4dcc47105c4038bba03025cb533
|
7
|
+
data.tar.gz: 8402eb677b0c1b24dbea124c48862e25dd39430585a0b44969383c78548c256267ca2c06d6755ea77e6e591b4209e74c5eb5e99f97af864c474aa17afcd1f37c
|
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
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -226,12 +226,42 @@ 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
|
+
# Quote array as a parenthesis-enclosed list of identifiers
|
253
|
+
def quote_identifier_list(values) = "(#{values.map { quote_identifier(_1) }.join(', ')})"
|
254
|
+
|
255
|
+
# Quote array as a parenthesis-enclosed list of literals
|
256
|
+
def quote_literal_list(values) = "(#{values.map { quote_literal(_1) }.join(', ')})"
|
257
|
+
|
229
258
|
# :call-seq:
|
230
259
|
# exist?(query)
|
231
260
|
# exist?(table, id)
|
232
261
|
# eists?(table, where_clause)
|
233
262
|
#
|
234
|
-
# Return true iff the query returns exactly one value
|
263
|
+
# Return true iff the query returns exactly one value. Use '!empty?' to
|
264
|
+
# check if the query returns one or more records
|
235
265
|
def exist?(*args)
|
236
266
|
arg1, arg2 = *args
|
237
267
|
query =
|
@@ -273,8 +303,9 @@ module PgConn
|
|
273
303
|
|
274
304
|
# Return a single value. It is an error if the query doesn't return a
|
275
305
|
# single record with a single column. If :transaction is true, the query
|
276
|
-
# will be executed in a transaction and be committed
|
277
|
-
# (the default).
|
306
|
+
# will be executed in a transaction and also be committed if :commit is
|
307
|
+
# true (this is the default). It can be used to execute 'insert' statements
|
308
|
+
# with a 'returning' clause
|
278
309
|
def value(query) #, transaction: false, commit: true)
|
279
310
|
r = pg_exec(query)
|
280
311
|
check_1c(r)
|
@@ -421,8 +452,11 @@ module PgConn
|
|
421
452
|
h
|
422
453
|
end
|
423
454
|
|
455
|
+
# TODO: #group - same as table but partitions a table on the given keys
|
456
|
+
# returning a map from key to array of records
|
457
|
+
|
424
458
|
# TODO: An #array method that returns a map from id to tuple. Hmm... almost
|
425
|
-
#
|
459
|
+
# the same as #map
|
426
460
|
|
427
461
|
# Return a hash from the record id column to an OpenStruct representation
|
428
462
|
# 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.
|
4
|
+
version: 0.12.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-
|
11
|
+
date: 2024-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|