pg_conn 0.23.0 → 0.25.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 +18 -6
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +35 -7
- 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: eb9303d38e0364b374379d8d0549d461decf393d1a20c5a97da42b1c0b0d7e17
|
4
|
+
data.tar.gz: 53512feaaff24b3b6e8b7366a0c860dac0d38f8880698570cfa16cffbb7a46b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9efb0689c559425bee8bebb5d984c72222e8bd2377803cc8c1415d5b253ada2f0913dc70b17ef12c0f9677b26e1db60accb5bdb66de41220f7001a2628c013c
|
7
|
+
data.tar.gz: fcd4f4e04157e2cdf10226f1a4545ab8fd66ce960cf14c732e0eceda9450e3c94b211277da303e8338aff7fbfbb3eb09bcd6b5946e979aa383f5f3b803ac86d7
|
data/TODO
CHANGED
@@ -1,4 +1,20 @@
|
|
1
1
|
TODO
|
2
|
+
|
3
|
+
o Instrumentation of connection object
|
4
|
+
|
5
|
+
# Augment conn object exec method to emit duration of the query
|
6
|
+
conn.define_singleton_method(:original_exec, conn.method(:exec))
|
7
|
+
conn.define_singleton_method(:exec) do |*args|
|
8
|
+
t0 = Time.now
|
9
|
+
r = original_exec(*args)
|
10
|
+
t1 = Time.now
|
11
|
+
@duration = ((t1 - t0) * 1000).round()
|
12
|
+
r
|
13
|
+
end
|
14
|
+
conn.define_singleton_method(:duration) do
|
15
|
+
@duration
|
16
|
+
end
|
17
|
+
|
2
18
|
o Use :elem_type everywhere
|
3
19
|
o Use 'drop ... cascade' everywhere
|
4
20
|
o db.context(schema: app_portal, transaction: true) { ... }
|
@@ -19,7 +35,6 @@ TODO
|
|
19
35
|
|
20
36
|
server.call :sp_nic_update_comtext, str_id, str_comtext, site.current_user.id
|
21
37
|
|
22
|
-
|
23
38
|
o Have a 'with' method that combines multiple brachet-methods:
|
24
39
|
|
25
40
|
conn.with(schema: public, transation: true) { ... }
|
@@ -34,9 +49,8 @@ TODO
|
|
34
49
|
struct # exists
|
35
50
|
structs
|
36
51
|
|
37
|
-
|
38
52
|
o Make rdbms, role, schema, and session methods part of a PgModel file that
|
39
|
-
monkey patch PgConn objects to include a #model method that returns the
|
53
|
+
monkey patch PgConn objects to include a #model method that returns the
|
40
54
|
top-level rdbms object
|
41
55
|
|
42
56
|
o #group method
|
@@ -67,8 +81,6 @@ TODO
|
|
67
81
|
end
|
68
82
|
end
|
69
83
|
|
70
|
-
|
71
|
-
|
72
84
|
o Use enumerators
|
73
85
|
o Use SQL parameters. Optionally with a different syntax:
|
74
86
|
$var - Value that gets single-quoted
|
@@ -93,7 +105,7 @@ TODO
|
|
93
105
|
# grant(role, to_role)
|
94
106
|
# grant(privilege, subject, to_role)
|
95
107
|
def grant(role, to_role)
|
96
|
-
#
|
108
|
+
#
|
97
109
|
conn.exec "grant #{role} to #{to_role}"
|
98
110
|
end
|
99
111
|
o Allow a :type argument to all query methods that can be used to specify the
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -220,6 +220,13 @@ module PgConn
|
|
220
220
|
@savepoints = nil # Stack of savepoint names. Nil if no transaction in progress
|
221
221
|
end
|
222
222
|
|
223
|
+
# Reset connection but keep noise level (TODO: How about the other
|
224
|
+
# per-session settings in #initialize? Are they cleared by #reset too?)
|
225
|
+
def reset
|
226
|
+
@pg_connection.reset
|
227
|
+
@pg_connection.exec "set client_min_messages to warning;" # Silence warnings
|
228
|
+
end
|
229
|
+
|
223
230
|
# Close the database connection. TODO: Rename 'close'
|
224
231
|
def terminate()
|
225
232
|
@pg_connection.close if @pg_connection && !@pg_connection.finished?
|
@@ -261,7 +268,7 @@ module PgConn
|
|
261
268
|
# of values
|
262
269
|
#
|
263
270
|
# The :elem_type option can be a postgres type name (String or Symbol) or
|
264
|
-
# an array of type names.
|
271
|
+
# an array of type names. It is used as the required explicit element
|
265
272
|
# type when the argument is an empty array. The element types shoud be in
|
266
273
|
# the same order as the array arguments. Nested arrays is not supported
|
267
274
|
#
|
@@ -579,14 +586,16 @@ module PgConn
|
|
579
586
|
h
|
580
587
|
end
|
581
588
|
|
582
|
-
# Return the value of calling the given function
|
583
|
-
# a Symbol and can contain the schema of the function). It dynamically
|
589
|
+
# Return the value of calling the given postgres function. It dynamically
|
584
590
|
# detects the structure of the result and return a value or an array of
|
585
591
|
# values if the result contained only one column (like #value or #values),
|
586
592
|
# a tuple if the record has multiple columns (like #tuple), and an array of
|
587
593
|
# of tuples if the result contained more than one record with multiple
|
588
|
-
# columns (like #tuples).
|
589
|
-
#
|
594
|
+
# columns (like #tuples).
|
595
|
+
#
|
596
|
+
# The name argument can be a String or a Symbol that may contain the schema
|
597
|
+
# of the function. If the :proc option is true the "function" is assumed
|
598
|
+
# to be a procedure
|
590
599
|
#
|
591
600
|
def call(name, *args, elem_type: nil, proc: false) # :proc may interfere with hashes
|
592
601
|
args_seq = quote_values(args, elem_type: elem_type)
|
@@ -621,7 +630,10 @@ module PgConn
|
|
621
630
|
#
|
622
631
|
# There is no variant that takes a single tuple because it would then be
|
623
632
|
# impossible to have array or hash field values
|
624
|
-
def insert(*args)
|
633
|
+
def insert(*args, upsert: nil, **opts)
|
634
|
+
# Add options to args except the special :upsert option
|
635
|
+
args << opts if !opts.empty?
|
636
|
+
|
625
637
|
# Add schema (=nil) if absent
|
626
638
|
args.unshift nil if args.size == 2 || (args.size == 3 && args[1].is_a?(Array))
|
627
639
|
|
@@ -656,17 +668,33 @@ module PgConn
|
|
656
668
|
fields ||= data.keys
|
657
669
|
tuples = [fields.map { |field| data[field] }]
|
658
670
|
else
|
659
|
-
raise ArgumentError
|
671
|
+
raise ArgumentError, "Illegal argument '#{data.inspect}'"
|
660
672
|
end
|
661
673
|
|
674
|
+
# On-conflict clause
|
675
|
+
upsert_sql =
|
676
|
+
case upsert
|
677
|
+
when true; "on conflict do nothing"
|
678
|
+
when String; "on conlict #{upsert}"
|
679
|
+
when false, nil; ""
|
680
|
+
else
|
681
|
+
raise ArgumentError, "Illegal value for :upsert option: #{upsert.inspect}"
|
682
|
+
end
|
683
|
+
|
662
684
|
# Execute SQL statement using either :value or :values depending on data arity
|
663
685
|
self.send method, %(
|
664
686
|
insert into #{table} (#{quote_identifiers(fields)})
|
665
687
|
values #{quote_tuples(tuples)}
|
688
|
+
#{upsert_sql}
|
666
689
|
returning id
|
667
690
|
)
|
668
691
|
end
|
669
692
|
|
693
|
+
# Use upsert. Currently on 'on conflict do nothing' is supported
|
694
|
+
def upsert(*args)
|
695
|
+
insert(*args, upsert: true)
|
696
|
+
end
|
697
|
+
|
670
698
|
# Update record(s)
|
671
699
|
def update(schema = nil, table, expr, hash)
|
672
700
|
table = [schema, table].compact.join(".")
|
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.25.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-
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|