pgtk 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +4 -20
- data/.github/workflows/codecov.yml +10 -26
- data/.github/workflows/copyrights.yml +4 -19
- data/.github/workflows/license.yml +4 -19
- data/.github/workflows/markdown-lint.yml +4 -19
- data/.github/workflows/pdd.yml +5 -20
- data/.github/workflows/rake.yml +9 -24
- data/.github/workflows/reuse.yml +21 -0
- data/.github/workflows/xcop.yml +4 -19
- data/.github/workflows/yamllint.yml +4 -19
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -20
- data/.rultor.yml +5 -21
- data/.simplecov +2 -19
- data/.yamllint.yml +2 -19
- data/Gemfile +10 -23
- data/Gemfile.lock +64 -34
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +11 -4
- data/REUSE.toml +17 -0
- data/Rakefile +8 -37
- data/cucumber.yml +2 -19
- data/lib/pgtk/liquibase_task.rb +3 -20
- data/lib/pgtk/pgsql_task.rb +3 -20
- data/lib/pgtk/pool.rb +36 -25
- data/lib/pgtk/spy.rb +36 -0
- data/lib/pgtk/version.rb +4 -21
- data/lib/pgtk/wire.rb +6 -23
- data/lib/pgtk.rb +3 -20
- data/pgtk.gemspec +2 -19
- data/resources/pom.xml +4 -23
- data/test/test__helper.rb +2 -19
- data/test/test_liquibase_task.rb +7 -22
- data/test/test_pgsql_task.rb +5 -22
- data/test/test_pool.rb +42 -34
- data/test-resources/2019/01-test.xml +2 -21
- data/test-resources/master.xml +2 -21
- metadata +6 -2
data/Gemfile.lock
CHANGED
@@ -47,11 +47,11 @@ GEM
|
|
47
47
|
benchmark (0.4.0)
|
48
48
|
bigdecimal (3.1.9)
|
49
49
|
builder (3.3.0)
|
50
|
-
concurrent-ruby (1.3.
|
51
|
-
connection_pool (2.
|
50
|
+
concurrent-ruby (1.3.5)
|
51
|
+
connection_pool (2.5.0)
|
52
52
|
crass (1.0.6)
|
53
53
|
date (3.4.1)
|
54
|
-
diff-lcs (1.
|
54
|
+
diff-lcs (1.6.0)
|
55
55
|
differ (0.1.2)
|
56
56
|
docile (1.4.1)
|
57
57
|
drb (2.2.1)
|
@@ -59,16 +59,18 @@ GEM
|
|
59
59
|
loog (> 0)
|
60
60
|
tago (> 0)
|
61
61
|
erubi (1.13.1)
|
62
|
-
i18n (1.14.
|
62
|
+
i18n (1.14.7)
|
63
63
|
concurrent-ruby (~> 1.0)
|
64
64
|
io-console (0.8.0)
|
65
|
-
irb (1.
|
65
|
+
irb (1.15.1)
|
66
|
+
pp (>= 0.6.0)
|
66
67
|
rdoc (>= 4.0.0)
|
67
68
|
reline (>= 0.4.2)
|
68
|
-
json (2.
|
69
|
-
language_server-protocol (3.17.0.
|
70
|
-
|
71
|
-
|
69
|
+
json (2.10.1)
|
70
|
+
language_server-protocol (3.17.0.4)
|
71
|
+
lint_roller (1.1.0)
|
72
|
+
logger (1.6.6)
|
73
|
+
loofah (2.24.0)
|
72
74
|
crass (~> 1.0.2)
|
73
75
|
nokogiri (>= 1.12.0)
|
74
76
|
loog (0.6.0)
|
@@ -78,26 +80,33 @@ GEM
|
|
78
80
|
builder
|
79
81
|
minitest (>= 5.0)
|
80
82
|
ruby-progressbar
|
81
|
-
nokogiri (1.18.
|
83
|
+
nokogiri (1.18.3-arm64-darwin)
|
82
84
|
racc (~> 1.4)
|
83
|
-
nokogiri (1.18.
|
85
|
+
nokogiri (1.18.3-x64-mingw-ucrt)
|
86
|
+
racc (~> 1.4)
|
87
|
+
nokogiri (1.18.3-x86_64-linux-gnu)
|
84
88
|
racc (~> 1.4)
|
85
89
|
parallel (1.26.3)
|
86
|
-
parser (3.3.
|
90
|
+
parser (3.3.7.1)
|
87
91
|
ast (~> 2.4.1)
|
88
92
|
racc
|
89
93
|
pg (1.5.9)
|
90
|
-
|
94
|
+
pg (1.5.9-x64-mingw-ucrt)
|
95
|
+
pp (0.6.2)
|
96
|
+
prettyprint
|
97
|
+
prettyprint (0.2.0)
|
98
|
+
psych (5.2.3)
|
91
99
|
date
|
92
100
|
stringio
|
93
|
-
qbash (0.
|
101
|
+
qbash (0.4.0)
|
94
102
|
backtrace (> 0)
|
95
103
|
elapsed (> 0)
|
96
104
|
loog (> 0)
|
97
105
|
tago (> 0)
|
98
106
|
racc (1.8.1)
|
99
|
-
rack (3.1.
|
100
|
-
rack-session (2.
|
107
|
+
rack (3.1.10)
|
108
|
+
rack-session (2.1.0)
|
109
|
+
base64 (>= 0.1.0)
|
101
110
|
rack (>= 3.0.0)
|
102
111
|
rack-test (2.2.0)
|
103
112
|
rack (>= 1.3)
|
@@ -120,14 +129,15 @@ GEM
|
|
120
129
|
zeitwerk (~> 2.6)
|
121
130
|
rainbow (3.1.1)
|
122
131
|
rake (13.2.1)
|
123
|
-
random-port (0.7.
|
124
|
-
|
132
|
+
random-port (0.7.5)
|
133
|
+
tago (> 0)
|
134
|
+
rdoc (6.12.0)
|
125
135
|
psych (>= 4.0.0)
|
126
136
|
regexp_parser (2.10.0)
|
127
137
|
reline (0.6.0)
|
128
138
|
io-console (~> 0.5)
|
129
|
-
rexml (3.4.
|
130
|
-
rspec-core (3.13.
|
139
|
+
rexml (3.4.1)
|
140
|
+
rspec-core (3.13.3)
|
131
141
|
rspec-support (~> 3.13.0)
|
132
142
|
rspec-expectations (3.13.3)
|
133
143
|
diff-lcs (>= 1.2.0, < 2.0)
|
@@ -144,20 +154,33 @@ GEM
|
|
144
154
|
rspec-mocks (~> 3.13)
|
145
155
|
rspec-support (~> 3.13)
|
146
156
|
rspec-support (3.13.2)
|
147
|
-
rubocop (1.
|
157
|
+
rubocop (1.72.2)
|
148
158
|
json (~> 2.3)
|
149
|
-
language_server-protocol (
|
159
|
+
language_server-protocol (~> 3.17.0.2)
|
160
|
+
lint_roller (~> 1.1.0)
|
150
161
|
parallel (~> 1.10)
|
151
162
|
parser (>= 3.3.0.2)
|
152
163
|
rainbow (>= 2.2.2, < 4.0)
|
153
164
|
regexp_parser (>= 2.9.3, < 3.0)
|
154
|
-
rubocop-ast (>= 1.
|
165
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
155
166
|
ruby-progressbar (~> 1.7)
|
156
167
|
unicode-display_width (>= 2.4.0, < 4.0)
|
157
|
-
rubocop-ast (1.
|
168
|
+
rubocop-ast (1.38.0)
|
158
169
|
parser (>= 3.3.1.0)
|
159
|
-
rubocop-
|
160
|
-
|
170
|
+
rubocop-minitest (0.37.1)
|
171
|
+
lint_roller (~> 1.1)
|
172
|
+
rubocop (>= 1.72.1, < 2.0)
|
173
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
174
|
+
rubocop-performance (1.24.0)
|
175
|
+
lint_roller (~> 1.1)
|
176
|
+
rubocop (>= 1.72.1, < 2.0)
|
177
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
178
|
+
rubocop-rake (0.7.1)
|
179
|
+
lint_roller (~> 1.1)
|
180
|
+
rubocop (>= 1.72.1)
|
181
|
+
rubocop-rspec (3.5.0)
|
182
|
+
lint_roller (~> 1.1)
|
183
|
+
rubocop (~> 1.72, >= 1.72.1)
|
161
184
|
ruby-progressbar (1.13.0)
|
162
185
|
securerandom (0.4.1)
|
163
186
|
simplecov (0.22.0)
|
@@ -170,40 +193,47 @@ GEM
|
|
170
193
|
simplecov-html (0.13.1)
|
171
194
|
simplecov_json_formatter (0.1.4)
|
172
195
|
slop (4.10.1)
|
173
|
-
stringio (3.1.
|
196
|
+
stringio (3.1.3)
|
174
197
|
tago (0.0.2)
|
175
198
|
thor (1.3.2)
|
176
199
|
tzinfo (2.0.6)
|
177
200
|
concurrent-ruby (~> 1.0)
|
178
|
-
unicode-display_width (3.1.
|
201
|
+
unicode-display_width (3.1.4)
|
179
202
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
180
203
|
unicode-emoji (4.0.4)
|
181
204
|
uri (1.0.2)
|
182
205
|
useragent (0.16.11)
|
183
|
-
xcop (0.
|
206
|
+
xcop (0.8.0)
|
184
207
|
differ (~> 0.1.2)
|
185
208
|
nokogiri (~> 1.10)
|
186
209
|
rainbow (~> 3.0)
|
187
210
|
slop (~> 4.4)
|
188
|
-
|
211
|
+
yard (0.9.37)
|
212
|
+
zeitwerk (2.7.2)
|
189
213
|
|
190
214
|
PLATFORMS
|
191
215
|
arm64-darwin-22
|
216
|
+
arm64-darwin-23
|
192
217
|
arm64-darwin-24
|
218
|
+
x64-mingw-ucrt
|
193
219
|
x86_64-linux
|
194
220
|
|
195
221
|
DEPENDENCIES
|
196
222
|
minitest (= 5.25.4)
|
197
223
|
minitest-reporters (~> 1.7)
|
198
224
|
pgtk!
|
199
|
-
rack (= 3.1.
|
225
|
+
rack (= 3.1.10)
|
200
226
|
rake (= 13.2.1)
|
201
227
|
rspec-rails (= 7.1.0)
|
202
|
-
rubocop (= 1.
|
203
|
-
rubocop-
|
228
|
+
rubocop (= 1.72.2)
|
229
|
+
rubocop-minitest (> 0)
|
230
|
+
rubocop-performance (> 0)
|
231
|
+
rubocop-rake (> 0)
|
232
|
+
rubocop-rspec (> 0)
|
204
233
|
simplecov (= 0.22.0)
|
205
234
|
simplecov-cobertura (~> 2.1)
|
206
|
-
xcop (
|
235
|
+
xcop (> 0)
|
236
|
+
yard (= 0.9.37)
|
207
237
|
|
208
238
|
BUNDLED WITH
|
209
239
|
2.5.16
|
data/LICENSE.txt
CHANGED
data/LICENSES/MIT.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -32,14 +32,14 @@ sudo apt-get install -y postgresql-10 postgresql-client-10
|
|
32
32
|
sudo apt-get install -y default-jre maven
|
33
33
|
```
|
34
34
|
|
35
|
-
Then, add this to your [
|
35
|
+
Then, add this to your [Gemfile](https://bundler.io/gemfile.html):
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
gem 'pgtk'
|
39
39
|
```
|
40
40
|
|
41
41
|
Then, add this to your
|
42
|
-
[
|
42
|
+
[Rakefile](https://github.com/ruby/rake/blob/master/doc/rakefile.rdoc):
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
require 'pgtk/pgsql_task'
|
@@ -73,7 +73,7 @@ Pgtk::LiquibaseTask.new liquibase: :pgsql do |t|
|
|
73
73
|
end
|
74
74
|
```
|
75
75
|
|
76
|
-
The config.yml file should be in this format:
|
76
|
+
The `config.yml` file should be in this format:
|
77
77
|
|
78
78
|
```yaml
|
79
79
|
pgsql:
|
@@ -151,7 +151,14 @@ module Minitest
|
|
151
151
|
end
|
152
152
|
```
|
153
153
|
|
154
|
-
|
154
|
+
You can also track all SQL queries sent through, with the help of `Pgtk::Pool`:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
require 'pgtk/spy'
|
158
|
+
pool = Pgtk::Spy.new(pool) do |sql|
|
159
|
+
# here, save this "sql" somewhere
|
160
|
+
end
|
161
|
+
```
|
155
162
|
|
156
163
|
Well, it works in
|
157
164
|
[netbout.com](https://github.com/yegor256/netbout),
|
data/REUSE.toml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
version = 1
|
5
|
+
[[annotations]]
|
6
|
+
path = [
|
7
|
+
".gitattributes",
|
8
|
+
".gitignore",
|
9
|
+
".gitleaksignore",
|
10
|
+
".pdd",
|
11
|
+
"Gemfile.lock",
|
12
|
+
"README.md",
|
13
|
+
"renovate.json"
|
14
|
+
]
|
15
|
+
precedence = "override"
|
16
|
+
SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
|
17
|
+
SPDX-License-Identifier = "MIT"
|
data/Rakefile
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'rubygems'
|
24
7
|
require 'rake'
|
@@ -33,7 +16,7 @@ def version
|
|
33
16
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
34
17
|
end
|
35
18
|
|
36
|
-
task default: %i[clean test rubocop xcop
|
19
|
+
task default: %i[clean test rubocop xcop yard]
|
37
20
|
|
38
21
|
require 'rake/testtask'
|
39
22
|
desc 'Run all unit tests'
|
@@ -44,13 +27,10 @@ Rake::TestTask.new(:test) do |test|
|
|
44
27
|
test.verbose = false
|
45
28
|
end
|
46
29
|
|
47
|
-
require '
|
48
|
-
desc 'Build
|
49
|
-
Rake::
|
50
|
-
|
51
|
-
rdoc.title = "#{name} #{version}"
|
52
|
-
rdoc.rdoc_files.include('README*')
|
53
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
require 'yard'
|
31
|
+
desc 'Build Yard documentation'
|
32
|
+
YARD::Rake::YardocTask.new do |t|
|
33
|
+
t.files = ['lib/**/*.rb']
|
54
34
|
end
|
55
35
|
|
56
36
|
require 'rubocop/rake_task'
|
@@ -63,15 +43,6 @@ end
|
|
63
43
|
require 'xcop/rake_task'
|
64
44
|
desc 'Validate all XML/XSL/XSD/HTML files for formatting'
|
65
45
|
Xcop::RakeTask.new :xcop do |task|
|
66
|
-
task.license = 'LICENSE.txt'
|
67
46
|
task.includes = ['**/*.xml', '**/*.xsl', '**/*.xsd', '**/*.html']
|
68
|
-
task.excludes = ['target/**/*', 'coverage/**/*', 'vendor/**/*']
|
69
|
-
end
|
70
|
-
|
71
|
-
task :copyright do
|
72
|
-
sh "grep -q -r '2019-#{Date.today.strftime('%Y')}' \
|
73
|
-
--include '*.rb' \
|
74
|
-
--include '*.txt' \
|
75
|
-
--include 'Rakefile' \
|
76
|
-
."
|
47
|
+
task.excludes = ['target/**/*', 'coverage/**/*', 'vendor/**/*', 'doc/**/*']
|
77
48
|
end
|
data/cucumber.yml
CHANGED
@@ -1,22 +1,5 @@
|
|
1
|
-
# Copyright (c) 2019-
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
20
3
|
---
|
21
4
|
default: --format pretty
|
22
5
|
travis: --format progress
|
data/lib/pgtk/liquibase_task.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'English'
|
24
7
|
require 'qbash'
|
@@ -30,7 +13,7 @@ require_relative '../pgtk'
|
|
30
13
|
|
31
14
|
# Liquibase rake task.
|
32
15
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
33
|
-
# Copyright:: Copyright (c) 2019-
|
16
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
34
17
|
# License:: MIT
|
35
18
|
class Pgtk::LiquibaseTask < Rake::TaskLib
|
36
19
|
attr_accessor :name, :master, :yaml, :quiet, :liquibase_version, :postgresql_version
|
data/lib/pgtk/pgsql_task.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'cgi'
|
24
7
|
require 'English'
|
@@ -33,7 +16,7 @@ require_relative '../pgtk'
|
|
33
16
|
|
34
17
|
# Pgsql rake task.
|
35
18
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
36
|
-
# Copyright:: Copyright (c) 2019-
|
19
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
37
20
|
# License:: MIT
|
38
21
|
class Pgtk::PgsqlTask < Rake::TaskLib
|
39
22
|
attr_accessor :name, :dir, :fresh_start, :user, :password, :dbname, :yaml, :quiet, :port, :config
|
data/lib/pgtk/pool.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'pg'
|
24
7
|
require 'loog'
|
@@ -27,10 +10,13 @@ require_relative 'wire'
|
|
27
10
|
|
28
11
|
# Pool.
|
29
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2019-
|
13
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
31
14
|
# License:: MIT
|
32
15
|
class Pgtk::Pool
|
33
16
|
# Constructor.
|
17
|
+
#
|
18
|
+
# @param [Pgtk::Wire] wire The wire
|
19
|
+
# @param [Object] log The log
|
34
20
|
def initialize(wire, log: Loog::NULL)
|
35
21
|
@wire = wire
|
36
22
|
@log = log
|
@@ -38,6 +24,8 @@ class Pgtk::Pool
|
|
38
24
|
end
|
39
25
|
|
40
26
|
# Get the version of PostgreSQL server.
|
27
|
+
#
|
28
|
+
# @return [String] Version of PostgreSQL server
|
41
29
|
def version
|
42
30
|
@version ||= exec('SHOW server_version')[0]['server_version'].split[0]
|
43
31
|
end
|
@@ -48,6 +36,8 @@ class Pgtk::Pool
|
|
48
36
|
# keep in mind that not all servers will allow you to have many connections
|
49
37
|
# open at the same time. For example, Heroku free PostgreSQL database
|
50
38
|
# allows only one connection open.
|
39
|
+
#
|
40
|
+
# @param [Integer] max Total amount of PostgreSQL connections in the pool
|
51
41
|
def start(max = 8)
|
52
42
|
max.times do
|
53
43
|
@pool << @wire.connection
|
@@ -101,6 +91,11 @@ class Pgtk::Pool
|
|
101
91
|
#
|
102
92
|
# More details about +exec_params+, which is called here, you can find
|
103
93
|
# here: https://www.rubydoc.info/gems/pg/0.17.1/PG%2FConnection:exec_params
|
94
|
+
#
|
95
|
+
# @param [String] query The SQL query with params inside (possibly)
|
96
|
+
# @param [Array] args List of arguments
|
97
|
+
# @param [Integer] result Should be 0 for text results, 1 for binary
|
98
|
+
# @yield [Hash] Rows
|
104
99
|
def exec(query, args = [], result = 0, &block)
|
105
100
|
connect do |c|
|
106
101
|
t = Txn.new(c, @log)
|
@@ -142,17 +137,33 @@ class Pgtk::Pool
|
|
142
137
|
@log = log
|
143
138
|
end
|
144
139
|
|
140
|
+
# Exec a single parameterized command.
|
141
|
+
# @param [String] query The SQL query with params inside (possibly)
|
142
|
+
# @param [Array] args List of arguments
|
143
|
+
# @param [Integer] result Should be 0 for text results, 1 for binary
|
144
|
+
# @yield [Hash] Rows
|
145
145
|
def exec(query, args = [], result = 0)
|
146
146
|
start = Time.now
|
147
147
|
sql = query.is_a?(Array) ? query.join(' ') : query
|
148
148
|
begin
|
149
|
-
out =
|
150
|
-
if
|
151
|
-
|
149
|
+
out =
|
150
|
+
if args.empty?
|
151
|
+
@conn.exec(sql) do |res|
|
152
|
+
if block_given?
|
153
|
+
yield res
|
154
|
+
else
|
155
|
+
res.each.to_a
|
156
|
+
end
|
157
|
+
end
|
152
158
|
else
|
153
|
-
res
|
159
|
+
@conn.exec_params(sql, args, result) do |res|
|
160
|
+
if block_given?
|
161
|
+
yield res
|
162
|
+
else
|
163
|
+
res.each.to_a
|
164
|
+
end
|
165
|
+
end
|
154
166
|
end
|
155
|
-
end
|
156
167
|
rescue StandardError => e
|
157
168
|
@log.error("#{sql}: #{e.message}")
|
158
169
|
raise e
|
data/lib/pgtk/spy.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require 'pg'
|
7
|
+
require 'loog'
|
8
|
+
require_relative '../pgtk'
|
9
|
+
require_relative 'wire'
|
10
|
+
|
11
|
+
# A pool tha spies on another pool.
|
12
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
14
|
+
# License:: MIT
|
15
|
+
class Pgtk::Spy
|
16
|
+
def initialize(pool, &block)
|
17
|
+
@pool = pool
|
18
|
+
@block = block
|
19
|
+
end
|
20
|
+
|
21
|
+
def version
|
22
|
+
@pool.version
|
23
|
+
end
|
24
|
+
|
25
|
+
def exec(sql, *args)
|
26
|
+
@block.call(sql)
|
27
|
+
@pool.exec(sql, *args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def transaction
|
31
|
+
@block.call('txn')
|
32
|
+
@pool.transaction do |t|
|
33
|
+
yield Spy.new(t, @block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/pgtk/version.rb
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../pgtk'
|
24
7
|
|
25
8
|
# Pgtk version.
|
26
9
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
-
# Copyright:: Copyright (c) 2019-
|
10
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
28
11
|
# License:: MIT
|
29
12
|
module Pgtk
|
30
13
|
# Current version of the library.
|
31
|
-
VERSION = '0.
|
14
|
+
VERSION = '0.13.0'
|
32
15
|
end
|