pgtk 0.32.4 → 0.32.6

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.
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'yaml'
7
+ require_relative '../../pgtk'
8
+ require_relative 'direct'
9
+
10
+ module Pgtk::Wire; end
11
+
12
+ # Using configuration from YAML file.
13
+ #
14
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
+ # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
16
+ # License:: MIT
17
+ class Pgtk::Wire::Yaml
18
+ # Constructor.
19
+ #
20
+ # @param [String] file Path to the YAML configuration file
21
+ # @param [String] node The root node name in the YAML file containing PostgreSQL configuration
22
+ # @param [Hash] opts Extra options forwarded to +PG.connect+ (e.g. +sslmode+,
23
+ # +connect_timeout+, +keepalives+). These override values from the YAML file.
24
+ def initialize(file, node = 'pgsql', **opts)
25
+ raise(ArgumentError, "The name of the file can't be nil") if file.nil?
26
+ @file = file
27
+ raise(ArgumentError, "The name of the node in the YAML file can't be nil") if node.nil?
28
+ @node = node
29
+ @opts = opts
30
+ end
31
+
32
+ # Create a new connection to PostgreSQL server.
33
+ def connection
34
+ raise(ArgumentError, "The file #{@file.inspect} not found") unless File.exist?(@file)
35
+ cfg = ::YAML.load_file(@file)
36
+ raise(ArgumentError, "The node '#{@node}' not found in YAML file #{@file.inspect}") unless cfg[@node]
37
+ Pgtk::Wire::Direct.new(
38
+ host: cfg[@node]['host'],
39
+ port: cfg[@node]['port'],
40
+ dbname: cfg[@node]['dbname'],
41
+ user: cfg[@node]['user'],
42
+ password: cfg[@node]['password'],
43
+ **cfg[@node].except(*%w[host port dbname user password url]).transform_keys(&:to_sym),
44
+ **@opts
45
+ ).connection
46
+ end
47
+ end
data/lib/pgtk/wire.rb CHANGED
@@ -3,10 +3,6 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
- require 'cgi'
7
- require 'pg'
8
- require 'uri'
9
- require 'yaml'
10
6
  require_relative '../pgtk'
11
7
 
12
8
  # Wires.
@@ -14,103 +10,8 @@ require_relative '../pgtk'
14
10
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
15
11
  # License:: MIT
16
12
  module Pgtk::Wire
17
- # Simple wire with details.
18
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
19
- # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
20
- # License:: MIT
21
- class Direct
22
- # Constructor.
23
- #
24
- # @param [String] host Host name of the PostgreSQL server
25
- # @param [Integer] port Port number of the PostgreSQL server
26
- # @param [String] dbname Database name
27
- # @param [String] user Username
28
- # @param [String] password Password
29
- # @param [Hash] opts Extra options forwarded to +PG.connect+ (e.g. +sslmode+,
30
- # +connect_timeout+, +keepalives+, +keepalives_idle+, +application_name+)
31
- def initialize(host:, port:, dbname:, user:, password:, **opts)
32
- raise(ArgumentError, "The host can't be nil") if host.nil?
33
- @host = host
34
- raise(ArgumentError, "The port can't be nil") if port.nil?
35
- @port = port
36
- @dbname = dbname
37
- @user = user
38
- @password = password
39
- @opts = opts
40
- end
41
-
42
- # Create a new connection to PostgreSQL server.
43
- def connection
44
- PG.connect(dbname: @dbname, host: @host, port: @port, user: @user, password: @password, **@opts)
45
- end
46
- end
47
-
48
- # Using ENV variable.
49
- #
50
- # The value of the variable should be in this format:
51
- #
52
- # postgres://user:password@host:port/dbname
53
- #
54
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
55
- # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
56
- # License:: MIT
57
- class Env
58
- # Constructor.
59
- #
60
- # @param [String] var The name of the environment variable with the connection URL
61
- # @param [Hash] opts Extra options forwarded to +PG.connect+ (e.g. +sslmode+,
62
- # +connect_timeout+, +keepalives+, +keepalives_idle+, +application_name+).
63
- # Explicit kwargs win over options carried in the URL query string on conflict.
64
- def initialize(var = 'DATABASE_URL', **opts)
65
- raise(ArgumentError, "The name of the environment variable can't be nil") if var.nil?
66
- @value = ENV.fetch(var, nil)
67
- raise(ArgumentError, "The environment variable #{@value.inspect} is not set") if @value.nil?
68
- @opts = opts
69
- end
70
-
71
- # Create a new connection to PostgreSQL server.
72
- def connection
73
- uri = URI(@value)
74
- extras = uri.query ? URI.decode_www_form(uri.query).to_h.transform_keys(&:to_sym) : {}
75
- Pgtk::Wire::Direct.new(
76
- host: CGI.unescape(uri.host),
77
- port: uri.port || 5432,
78
- dbname: CGI.unescape(uri.path[1..]),
79
- user: CGI.unescape(uri.userinfo.split(':')[0]),
80
- password: CGI.unescape(uri.userinfo.split(':')[1]),
81
- **extras.merge(@opts)
82
- ).connection
83
- end
84
- end
85
-
86
- # Using configuration from YAML file.
87
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
88
- # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
89
- # License:: MIT
90
- class Yaml
91
- # Constructor.
92
- #
93
- # @param [String] file Path to the YAML configuration file
94
- # @param [String] node The root node name in the YAML file containing PostgreSQL configuration
95
- def initialize(file, node = 'pgsql')
96
- raise(ArgumentError, "The name of the file can't be nil") if file.nil?
97
- @file = file
98
- raise(ArgumentError, "The name of the node in the YAML file can't be nil") if node.nil?
99
- @node = node
100
- end
101
-
102
- # Create a new connection to PostgreSQL server.
103
- def connection
104
- raise(ArgumentError, "The file #{@file.inspect} not found") unless File.exist?(@file)
105
- cfg = YAML.load_file(@file)
106
- raise(ArgumentError, "The node '#{@node}' not found in YAML file #{@file.inspect}") unless cfg[@node]
107
- Pgtk::Wire::Direct.new(
108
- host: cfg[@node]['host'],
109
- port: cfg[@node]['port'],
110
- dbname: cfg[@node]['dbname'],
111
- user: cfg[@node]['user'],
112
- password: cfg[@node]['password']
113
- ).connection
114
- end
115
- end
116
13
  end
14
+
15
+ require_relative 'wire/direct'
16
+ require_relative 'wire/env'
17
+ require_relative 'wire/yaml'
data/pgtk.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
27
  s.rdoc_options = ['--charset=UTF-8']
28
28
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
29
- s.add_dependency('backtrace', '~>0.4')
29
+ s.add_dependency('cgi', '~>0.0')
30
30
  s.add_dependency('concurrent-ruby', '~>1.3')
31
31
  s.add_dependency('donce', '~>0.0')
32
32
  s.add_dependency('ellipsized', '~>0.3')
data/resources/pom.xml CHANGED
@@ -10,7 +10,7 @@
10
10
  <version>0.0.0</version>
11
11
  <packaging>pom</packaging>
12
12
  <properties>
13
- <postgresql.version>42.7.11</postgresql.version>
13
+ <postgresql.version>42.7.12</postgresql.version>
14
14
  <liquibase.version>5.0.3</liquibase.version>
15
15
  </properties>
16
16
  <dependencies>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.4
4
+ version: 0.32.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -10,19 +10,19 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: backtrace
13
+ name: cgi
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.4'
18
+ version: '0.0'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.4'
25
+ version: '0.0'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: concurrent-ruby
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -197,15 +197,24 @@ files:
197
197
  - cucumber.yml
198
198
  - lib/pgtk.rb
199
199
  - lib/pgtk/impatient.rb
200
+ - lib/pgtk/impatient/too_slow.rb
200
201
  - lib/pgtk/liquibase_task.rb
201
202
  - lib/pgtk/liquicheck_task.rb
203
+ - lib/pgtk/liquicheck_task/must_error.rb
202
204
  - lib/pgtk/pgsql_task.rb
203
205
  - lib/pgtk/pool.rb
206
+ - lib/pgtk/pool/busy.rb
207
+ - lib/pgtk/pool/iterable_queue.rb
208
+ - lib/pgtk/pool/txn.rb
204
209
  - lib/pgtk/retry.rb
210
+ - lib/pgtk/retry/exhausted.rb
205
211
  - lib/pgtk/spy.rb
206
212
  - lib/pgtk/stash.rb
207
213
  - lib/pgtk/version.rb
208
214
  - lib/pgtk/wire.rb
215
+ - lib/pgtk/wire/direct.rb
216
+ - lib/pgtk/wire/env.rb
217
+ - lib/pgtk/wire/yaml.rb
209
218
  - pgtk.gemspec
210
219
  - resources/pom.xml
211
220
  - test-resources/2019/01-test.xml