pg 1.4.6 → 1.6.1
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
- checksums.yaml.gz.sig +0 -0
- data/{History.md → CHANGELOG.md} +185 -3
- data/Gemfile +12 -3
- data/README-Windows.rdoc +1 -1
- data/README.ja.md +75 -41
- data/README.md +86 -31
- data/Rakefile +95 -14
- data/certs/kanis@comcard.de.pem +20 -0
- data/certs/larskanis-2024.pem +24 -0
- data/ext/errorcodes.def +4 -5
- data/ext/errorcodes.txt +2 -5
- data/ext/extconf.rb +165 -14
- data/ext/gvl_wrappers.c +13 -2
- data/ext/gvl_wrappers.h +33 -0
- data/ext/pg.c +28 -35
- data/ext/pg.h +18 -14
- data/ext/pg_binary_decoder.c +231 -0
- data/ext/pg_binary_encoder.c +427 -0
- data/ext/pg_cancel_connection.c +360 -0
- data/ext/pg_coder.c +70 -12
- data/ext/pg_connection.c +473 -208
- data/ext/pg_copy_coder.c +316 -23
- data/ext/pg_record_coder.c +12 -11
- data/ext/pg_result.c +102 -30
- data/ext/pg_text_decoder.c +31 -10
- data/ext/pg_text_encoder.c +58 -26
- data/ext/pg_tuple.c +36 -33
- data/ext/pg_type_map.c +4 -3
- data/ext/pg_type_map_all_strings.c +3 -3
- data/ext/pg_type_map_by_class.c +6 -4
- data/ext/pg_type_map_by_column.c +9 -4
- data/ext/pg_type_map_by_mri_type.c +1 -1
- data/ext/pg_type_map_by_oid.c +10 -5
- data/ext/pg_type_map_in_ruby.c +6 -3
- data/lib/pg/basic_type_map_based_on_result.rb +21 -1
- data/lib/pg/basic_type_map_for_queries.rb +23 -10
- data/lib/pg/basic_type_map_for_results.rb +26 -3
- data/lib/pg/basic_type_registry.rb +46 -36
- data/lib/pg/binary_decoder/date.rb +9 -0
- data/lib/pg/binary_decoder/timestamp.rb +26 -0
- data/lib/pg/binary_encoder/timestamp.rb +20 -0
- data/lib/pg/cancel_connection.rb +53 -0
- data/lib/pg/coder.rb +18 -14
- data/lib/pg/connection.rb +387 -172
- data/lib/pg/exceptions.rb +6 -0
- data/lib/pg/text_decoder/date.rb +21 -0
- data/lib/pg/text_decoder/inet.rb +9 -0
- data/lib/pg/text_decoder/json.rb +17 -0
- data/lib/pg/text_decoder/numeric.rb +9 -0
- data/lib/pg/text_decoder/timestamp.rb +30 -0
- data/lib/pg/text_encoder/date.rb +13 -0
- data/lib/pg/text_encoder/inet.rb +31 -0
- data/lib/pg/text_encoder/json.rb +17 -0
- data/lib/pg/text_encoder/numeric.rb +9 -0
- data/lib/pg/text_encoder/timestamp.rb +24 -0
- data/lib/pg/version.rb +1 -1
- data/lib/pg.rb +78 -17
- data/misc/yugabyte/Dockerfile +9 -0
- data/misc/yugabyte/docker-compose.yml +28 -0
- data/misc/yugabyte/pg-test.rb +45 -0
- data/pg.gemspec +9 -5
- data/ports/patches/krb5/1.21.3/0001-Allow-static-linking-krb5-library.patch +30 -0
- data/ports/patches/openssl/3.5.1/0001-aarch64-mingw.patch +21 -0
- data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
- data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch +52 -0
- data/rakelib/pg_gem_helper.rb +64 -0
- data.tar.gz.sig +0 -0
- metadata +61 -49
- metadata.gz.sig +0 -0
- data/.appveyor.yml +0 -42
- data/.gems +0 -6
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +0 -117
- data/.github/workflows/source-gem.yml +0 -137
- data/.gitignore +0 -19
- data/.hgsigs +0 -34
- data/.hgtags +0 -41
- data/.irbrc +0 -23
- data/.pryrc +0 -23
- data/.tm_properties +0 -21
- data/.travis.yml +0 -49
- data/Manifest.txt +0 -72
- data/Rakefile.cross +0 -298
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/translation/.po4a-version +0 -7
- data/translation/po/all.pot +0 -875
- data/translation/po/ja.po +0 -868
- data/translation/po4a.cfg +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c220f1cc5cfd8e07690949fcf30a96abd8f710bc64f0c358eb6452288966a5b4
|
4
|
+
data.tar.gz: cd5f28d3098e2537e04dc218c8809b83308cb541e6b17891220559d33e2ada82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5de3fb30c6da95937d6c8913c9e172a348fa376edc6f06cc9333669c908a25cb2af85853aafbdc6839407f6b4aea93ca97e3b5b53f7182732664ecd6cd81e33
|
7
|
+
data.tar.gz: 00f5c6e8c359e81bf7c9145b7322583e511d440f681d32192430d9ce96772f1d71f8abce35e12ccf126d96a552205e799efee2533c54a84c623fa0aeee5c1c3c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{History.md → CHANGELOG.md}
RENAMED
@@ -1,3 +1,185 @@
|
|
1
|
+
## v1.6.1 [2025-08-03] Lars Kanis <lars@greiz-reinsdorf.de>
|
2
|
+
|
3
|
+
- Add binary gems for platforms `aarch64-linux-musl` and `x86_64-linux-musl` without the need to install package `gcompat`. [#657](https://github.com/ged/ruby-pg/pull/657).
|
4
|
+
- Serialize CompositeCoder#dimensions only when set. [#652](https://github.com/ged/ruby-pg/pull/652)
|
5
|
+
This fixes the compatibility to pg-1.5.9, when deserializing Marshal data from pg-1.6, as long as the new attribute isn't used.
|
6
|
+
- Remove dependency to MSYS2 package "postgresql" from binary Windows gem [#654](https://github.com/ged/ruby-pg/pull/654)
|
7
|
+
|
8
|
+
|
9
|
+
## v1.6.0 [2025-07-27] Lars Kanis <lars@greiz-reinsdorf.de>
|
10
|
+
|
11
|
+
Added:
|
12
|
+
|
13
|
+
- Add binary gems for Ruby 3.4.
|
14
|
+
- Add fat binary gem for platform `aarch64-mingw-ucrt` aka Windows on ARM [#626](https://github.com/ged/ruby-pg/pull/626), for platform Macos on Intel and ARM [#643](https://github.com/ged/ruby-pg/pull/643), for platform `aarch64-linux` [#646](https://github.com/ged/ruby-pg/pull/646) and for platform `x86_64-linux` [#551](https://github.com/ged/ruby-pg/pull/551#issuecomment-2504715762).
|
15
|
+
- Update fat binary gem to OpenSSL-3.5.1 and PostgreSQL-17.5.
|
16
|
+
- Add a patch to libpq to avoid starvation on bigger SSL records, which some database engines other than vanilla PostgreSQL use.
|
17
|
+
This patch applies to platform specific binary gems only.
|
18
|
+
[#616](https://github.com/ged/ruby-pg/pull/616)
|
19
|
+
- Add support for new query cancel functions of PostgreSQL-17.
|
20
|
+
This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions.
|
21
|
+
If the new functions are available they are used and the older are no longer compiled in.
|
22
|
+
This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key`.
|
23
|
+
[#614](https://github.com/ged/ruby-pg/pull/614)
|
24
|
+
- Add PG::BinaryDecoder::Array and PG::BinaryEncoder::Array to parse and encode PostgreSQL arrays in binary format.
|
25
|
+
[#603](https://github.com/ged/ruby-pg/pull/603)
|
26
|
+
- Add possibility to define the number of array dimensions to be encoded.
|
27
|
+
Setting dimensions is especially useful, when a Record shall be encoded into an Array, since the Array encoder can not distinguish if the array shall be encoded as a higher dimension or as a record otherwise.
|
28
|
+
[#622](https://github.com/ged/ruby-pg/pull/622)
|
29
|
+
- Add Connection#set_chunked_rows_mode [#610](https://github.com/ged/ruby-pg/pull/610)
|
30
|
+
- Add PG::Connection#close_prepared, PG::Connection#close_portal, PG::Connection#send_close_prepared and PG::Connection#send_close_portal which are new in PostgreSQL-17.
|
31
|
+
[#611](https://github.com/ged/ruby-pg/pull/611)
|
32
|
+
- Add Connection#send_pipeline_sync, async_pipeline_sync and release GVL at PQ(sendP|P)ipelineSync.
|
33
|
+
[#612](https://github.com/ged/ruby-pg/pull/612)
|
34
|
+
- Add MINGW package dependency which is resolved by RubyInstaller.
|
35
|
+
[#617](https://github.com/ged/ruby-pg/pull/617)
|
36
|
+
- Change `conn.server_version` and `conn.protocol_version` to raise instead of return 0 on error.
|
37
|
+
[#632](https://github.com/ged/ruby-pg/pull/632)
|
38
|
+
- Fix connecting to multiple hosts after `connnect_timeout`.
|
39
|
+
[#637](https://github.com/ged/ruby-pg/pull/637)
|
40
|
+
- Fix making PG::BasicTypeMapForQueries shareable for Ractor in ruby-3.5.
|
41
|
+
[#636](https://github.com/ged/ruby-pg/pull/636)
|
42
|
+
- Fix missing array input verification in PG::TypeMapByColumn.
|
43
|
+
This could cause a segfault.
|
44
|
+
[#620](https://github.com/ged/ruby-pg/pull/620)
|
45
|
+
- Rename `History.md` to `CHANGELOG.md`, which is more common.
|
46
|
+
[#642](https://github.com/ged/ruby-pg/pull/642)
|
47
|
+
|
48
|
+
Removed:
|
49
|
+
|
50
|
+
- Drop support of Ruby < 2.7 [#606](https://github.com/ged/ruby-pg/pull/606)
|
51
|
+
- Drop support of PostgreSQL < 10 [#606](https://github.com/ged/ruby-pg/pull/606)
|
52
|
+
- Remove workaround for Truffleruby < 21.3.0 [#613](https://github.com/ged/ruby-pg/pull/613)
|
53
|
+
|
54
|
+
|
55
|
+
## v1.5.9 [2024-10-24] Lars Kanis <lars@greiz-reinsdorf.de>
|
56
|
+
|
57
|
+
- Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595)
|
58
|
+
- Remove raising `conect_timeout` from 1 to 2 seconds. [#590](https://github.com/ged/ruby-pg/pull/590)
|
59
|
+
- Fix binary copy_data in Ractor context. [#594](https://github.com/ged/ruby-pg/pull/594)
|
60
|
+
- Exclude CI files and hidden files from built gem. [#591](https://github.com/ged/ruby-pg/pull/591)
|
61
|
+
This is to simplify security inspection.
|
62
|
+
- Update error classes to PostgreSQL-17.
|
63
|
+
- Update Windows fat binary gem to OpenSSL-3.4.0 and PostgreSQL-17.0.
|
64
|
+
|
65
|
+
|
66
|
+
## v1.5.8 [2024-09-06] Lars Kanis <lars@greiz-reinsdorf.de>
|
67
|
+
|
68
|
+
- Fix host list duplication every time conn.reset is used. [#586](https://github.com/ged/ruby-pg/pull/586)
|
69
|
+
- Add default decoder for anonymous record types to BasicTypeRegistry [#579](https://github.com/ged/ruby-pg/pull/579)
|
70
|
+
- Update Windows fat binary gem to OpenSSL-3.3.2 and PostgreSQL-16.4.
|
71
|
+
|
72
|
+
|
73
|
+
## v1.5.7 [2024-07-28] Lars Kanis <lars@greiz-reinsdorf.de>
|
74
|
+
|
75
|
+
- Remove deprecated use of fptr->fd.[#562](https://github.com/ged/ruby-pg/pull/562)
|
76
|
+
Direct access is disallowed since ruby-3.4.
|
77
|
+
- Make `pgconn_connect_poll` close the socket prior to calling `PQconnectPoll`. [#564](https://github.com/ged/ruby-pg/pull/564)
|
78
|
+
This could result in an exception while connecting when used multi threaded.
|
79
|
+
- Fix several typos and improve spelling in documentation and code. [#566](https://github.com/ged/ruby-pg/pull/566)
|
80
|
+
- Add missing PG::RollbackTransaction as an option to exit conn.transaction. [#560](https://github.com/ged/ruby-pg/pull/560)
|
81
|
+
Usage like in rails: https://api.rubyonrails.org/classes/ActiveRecord/Rollback.html
|
82
|
+
- Don't print a warning when bigdecimal is required on ruby-3.4+ [#574](https://github.com/ged/ruby-pg/pull/574)
|
83
|
+
- Update Windows fat binary gem to OpenSSL-3.3.1 and PostgreSQL-16.3.
|
84
|
+
|
85
|
+
|
86
|
+
## v1.5.6 [2024-03-01] Lars Kanis <lars@greiz-reinsdorf.de>
|
87
|
+
|
88
|
+
- Renew address resolution (DNS) in conn.reset. [#558](https://github.com/ged/ruby-pg/pull/558)
|
89
|
+
This is important, if DNS is used for load balancing, etc.
|
90
|
+
- Make bigdecimal an optional dependency. [#556](https://github.com/ged/ruby-pg/pull/556)
|
91
|
+
It's a gem in ruby-3.4+, so that users shouldn't be forced to use it.
|
92
|
+
|
93
|
+
|
94
|
+
## v1.5.5 [2024-02-15] Lars Kanis <lars@greiz-reinsdorf.de>
|
95
|
+
|
96
|
+
- Explicitly retype timespec fields to int64_t to fix compatibility with 32bit arches. [#547](https://github.com/ged/ruby-pg/pull/547)
|
97
|
+
- Fix possible buffer overflows in PG::BinaryDecoder::CopyRow on 32 bit systems. [#548](https://github.com/ged/ruby-pg/pull/548)
|
98
|
+
- Add binary Windows gems for Ruby 3.3.
|
99
|
+
- Update Windows fat binary gem to OpenSSL-3.2.1 and PostgreSQL-16.2.
|
100
|
+
|
101
|
+
|
102
|
+
## v1.5.4 [2023-09-01] Lars Kanis <lars@greiz-reinsdorf.de>
|
103
|
+
|
104
|
+
- Fix compiling the pg extension with MSVC 2022. [#535](https://github.com/ged/ruby-pg/pull/535)
|
105
|
+
- Set PG::Connection's encoding even if setting client_encoding on connection startup fails. [#541](https://github.com/ged/ruby-pg/pull/541)
|
106
|
+
- Don't set the server's client_encoding if it's unnecessary. [#542](https://github.com/ged/ruby-pg/pull/542)
|
107
|
+
This is important for connection proxies, who disallow configuration settings.
|
108
|
+
- Update Windows fat binary gem to OpenSSL-3.1.2 and PostgreSQL-15.4.
|
109
|
+
|
110
|
+
|
111
|
+
## v1.5.3 [2023-04-28] Lars Kanis <lars@greiz-reinsdorf.de>
|
112
|
+
|
113
|
+
- Fix possible segfault when creating a new PG::Result with type map. [#530](https://github.com/ged/ruby-pg/pull/530)
|
114
|
+
- Add category to deprecation warnings of Coder.new, so that they are suppressed for most users. [#528](https://github.com/ged/ruby-pg/pull/528)
|
115
|
+
|
116
|
+
|
117
|
+
## v1.5.2 [2023-04-26] Lars Kanis <lars@greiz-reinsdorf.de>
|
118
|
+
|
119
|
+
- Fix regression in copy_data regarding binary format when using no coder. [#527](https://github.com/ged/ruby-pg/pull/527)
|
120
|
+
|
121
|
+
|
122
|
+
## v1.5.1 [2023-04-24] Lars Kanis <lars@greiz-reinsdorf.de>
|
123
|
+
|
124
|
+
- Don't overwrite flags of timestamp coders. [#524](https://github.com/ged/ruby-pg/pull/524)
|
125
|
+
Fixes a regression in rails: https://github.com/rails/rails/issues/48049
|
126
|
+
|
127
|
+
|
128
|
+
## v1.5.0 [2023-04-24] Lars Kanis <lars@greiz-reinsdorf.de>
|
129
|
+
|
130
|
+
Enhancements:
|
131
|
+
|
132
|
+
- Better support for binary format:
|
133
|
+
- Extend PG::Connection#copy_data to better support binary transfers [#511](https://github.com/ged/ruby-pg/pull/511)
|
134
|
+
- Add binary COPY encoder and decoder:
|
135
|
+
* PG::BinaryEncoder::CopyRow
|
136
|
+
* PG::BinaryDecoder::CopyRow
|
137
|
+
- Add binary timestamp encoders:
|
138
|
+
* PG::BinaryEncoder::TimestampUtc
|
139
|
+
* PG::BinaryEncoder::TimestampLocal
|
140
|
+
* PG::BinaryEncoder::Timestamp
|
141
|
+
- Add PG::BinaryEncoder::Float4 and Float8
|
142
|
+
- Add binary date type: [#515](https://github.com/ged/ruby-pg/pull/515)
|
143
|
+
* PG::BinaryEncoder::Date
|
144
|
+
* PG::BinaryDecoder::Date
|
145
|
+
- Add PG::Result#binary_tuples [#511](https://github.com/ged/ruby-pg/pull/511)
|
146
|
+
It is useful for COPY and not deprecated in that context.
|
147
|
+
- Add PG::TextEncoder::Bytea to BasicTypeRegistry [#506](https://github.com/ged/ruby-pg/pull/506)
|
148
|
+
- Ractor support: [#519](https://github.com/ged/ruby-pg/pull/519)
|
149
|
+
- Pg is now fully compatible with Ractor introduced in Ruby-3.0 and doesn't use any global mutable state.
|
150
|
+
- All type en/decoders and type maps are shareable between ractors if they are made frozen by `Ractor.make_shareable`.
|
151
|
+
- Also frozen PG::Result and PG::Tuple objects can be shared.
|
152
|
+
- All frozen objects (except PG::Connection) can still be used to do communication with the PostgreSQL server or to read retrieved data.
|
153
|
+
- PG::Connection is not shareable and must be created within each Ractor to establish a dedicated connection.
|
154
|
+
- Use keyword arguments instead of hashes for Coder initialization and #to_h. [#511](https://github.com/ged/ruby-pg/pull/511)
|
155
|
+
- Add PG::Result.res_status as a class method and extend Result#res_status to return the status of self. [#508](https://github.com/ged/ruby-pg/pull/508)
|
156
|
+
- Reduce the number of files loaded at `require 'pg'` by using autoload. [#513](https://github.com/ged/ruby-pg/pull/513)
|
157
|
+
Previously stdlib libraries `date`, `json`, `ipaddr` and `bigdecimal` were static dependencies, but now only `socket` is mandatory.
|
158
|
+
- Improve garbage collector performance by adding write barriers to all PG classes. [#518](https://github.com/ged/ruby-pg/pull/518)
|
159
|
+
Now they can be promoted to the old generation, which means they only get marked on major GC.
|
160
|
+
- New method PG::Connection#check_socket to check the socket state. [#521](https://github.com/ged/ruby-pg/pull/521)
|
161
|
+
- Mark many internal constants as private. [#522](https://github.com/ged/ruby-pg/pull/522)
|
162
|
+
- Update Windows fat binary gem to OpenSSL-3.1.0.
|
163
|
+
|
164
|
+
Bugfixes:
|
165
|
+
|
166
|
+
- Move nfields-check of stream-methods after result status check [#507](https://github.com/ged/ruby-pg/pull/507)
|
167
|
+
This ensures that the nfield-check doesn't hide errors like statement timeout.
|
168
|
+
|
169
|
+
Removed:
|
170
|
+
|
171
|
+
- Remove deprecated PG::BasicTypeRegistry.register_type and co. [Part of #519](https://github.com/ged/ruby-pg/commit/2919ee1a0c6b216e18e1d06c95c2616ef69d2f97)
|
172
|
+
- Add deprecation warning about PG::Coder initialization per Hash argument. [#514](https://github.com/ged/ruby-pg/pull/514)
|
173
|
+
It is recommended to use keyword arguments instead.
|
174
|
+
- The internal encoding cache was removed. [#516](https://github.com/ged/ruby-pg/pull/516)
|
175
|
+
It shouldn't have a practical performance impact.
|
176
|
+
|
177
|
+
Repository:
|
178
|
+
|
179
|
+
- `rake test` tries to find PostgreSQL server commands by pg_config [#503](https://github.com/ged/ruby-pg/pull/503)
|
180
|
+
So there's no need to set the PATH manually any longer.
|
181
|
+
|
182
|
+
|
1
183
|
## v1.4.6 [2023-02-26] Lars Kanis <lars@greiz-reinsdorf.de>
|
2
184
|
|
3
185
|
- Add japanese README file. [#502](https://github.com/ged/ruby-pg/pull/502)
|
@@ -64,7 +246,7 @@ Added:
|
|
64
246
|
Bugfixes:
|
65
247
|
|
66
248
|
- Try IPv6 and IPv4 addresses, if DNS resolves to both. [#452](https://github.com/ged/ruby-pg/pull/452)
|
67
|
-
- Re-add block-call semantics to PG::Connection.new
|
249
|
+
- Re-add block-call semantics to PG::Connection.new accidentally removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454)
|
68
250
|
- Handle client error after all data consumed in #copy_data for output. [#455](https://github.com/ged/ruby-pg/pull/455)
|
69
251
|
- Avoid spurious keyword argument warning on Ruby 2.7. [#456](https://github.com/ged/ruby-pg/pull/456)
|
70
252
|
- Change connection setup to respect connect_timeout parameter. [#459](https://github.com/ged/ruby-pg/pull/459)
|
@@ -103,7 +285,7 @@ Bugfixes:
|
|
103
285
|
|
104
286
|
- Don't leak IO in case of connection errors. [#439](https://github.com/ged/ruby-pg/pull/439)
|
105
287
|
Previously it was kept open until the PG::Connection was garbage collected.
|
106
|
-
- Fix a performance
|
288
|
+
- Fix a performance regression in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442)
|
107
289
|
- Fix occasional error Errno::EBADF (Bad file descriptor) while connecting. [#444](https://github.com/ged/ruby-pg/pull/444)
|
108
290
|
- Fix compatibility of res.stream_each* methods with Fiber.scheduler. [#446](https://github.com/ged/ruby-pg/pull/446)
|
109
291
|
- Remove FL_TEST and FL_SET, which are MRI-internal. [#437](https://github.com/ged/ruby-pg/pull/437)
|
@@ -189,7 +371,7 @@ Type cast enhancements:
|
|
189
371
|
- Add PG::BasicTypeMapForQueries::BinaryData for encoding of bytea columns. [#348](https://github.com/ged/ruby-pg/pull/348)
|
190
372
|
- Reduce time to build coder maps and permit to reuse them for several type maps per PG::BasicTypeRegistry::CoderMapsBundle.new(conn) . [#376](https://github.com/ged/ruby-pg/pull/376)
|
191
373
|
- Make BasicTypeRegistry a class and use a global default instance of it.
|
192
|
-
Now a local type registry can be
|
374
|
+
Now a local type registry can be instantiated and given to the type map, to avoid changing shared global states.
|
193
375
|
- Allow PG::BasicTypeMapForQueries to take a Proc as callback for undefined types.
|
194
376
|
|
195
377
|
Other Enhancements:
|
data/Gemfile
CHANGED
@@ -5,10 +5,19 @@ gemspec
|
|
5
5
|
|
6
6
|
source "https://rubygems.org/"
|
7
7
|
|
8
|
-
group :development
|
8
|
+
group :development do
|
9
|
+
gem "rdoc", "~> 6.4"
|
10
|
+
gem "mini_portile2", "~> 2.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
9
14
|
gem "bundler", ">= 1.16", "< 3.0"
|
10
15
|
gem "rake-compiler", "~> 1.0"
|
11
|
-
gem "rake-compiler-dock", "~> 1.
|
12
|
-
gem "rdoc", "~> 6.4"
|
16
|
+
gem "rake-compiler-dock", "~> 1.9.1"
|
13
17
|
gem "rspec", "~> 3.5"
|
18
|
+
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
|
19
|
+
# Specs should succeed without it, but 4 examples are then excluded.
|
20
|
+
# With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
|
21
|
+
# That way we can check both situations in CI.
|
22
|
+
# gem "bigdecimal", "~> 3.0"
|
14
23
|
end
|
data/README-Windows.rdoc
CHANGED
@@ -41,7 +41,7 @@ sure it is started. A native Docker installation is best on Linux.
|
|
41
41
|
|
42
42
|
Then run:
|
43
43
|
|
44
|
-
rake gem:
|
44
|
+
rake gem:native
|
45
45
|
|
46
46
|
This will download a docker image suited for building windows gems, and it
|
47
47
|
will download and build OpenSSL and PostgreSQL. Finally the gem is built
|
data/README.ja.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# pg
|
2
2
|
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
3
|
+
* ホーム :: https://github.com/ged/ruby-pg
|
4
|
+
* ドキュメント :: http://deveiate.org/code/pg (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
|
5
|
+
* 変更履歴 :: link:/CHANGELOG.md
|
6
6
|
|
7
7
|
[](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Pgは[PostgreSQL
|
14
14
|
RDBMS](http://www.postgresql.org/)へのRubyのインターフェースです。[PostgreSQL
|
15
|
-
|
15
|
+
10以降](http://www.postgresql.org/support/versioning/)で動作します。
|
16
16
|
|
17
17
|
簡単な使用例は次の通りです。
|
18
18
|
```ruby
|
@@ -41,8 +41,8 @@ Actionsのビルド状況](https://github.com/ged/ruby-pg/actions/workflows/sour
|
|
41
41
|
|
42
42
|
## 要件
|
43
43
|
|
44
|
-
* Ruby 2.
|
45
|
-
* PostgreSQL
|
44
|
+
* Ruby 2.7かそれより新しいバージョン
|
45
|
+
* PostgreSQL 10.xかそれ以降のバージョン(ヘッダー付属のもの、例えば-devの名前のパッケージ)。
|
46
46
|
|
47
47
|
それより前のバージョンのRubyやPostgreSQLでも通常は同様に動作しますが、定期的なテストはされていません。
|
48
48
|
|
@@ -83,8 +83,9 @@ README-Windows.rdoc を参照してください。
|
|
83
83
|
|
84
84
|
## 型変換
|
85
85
|
|
86
|
-
Pg
|
87
|
-
|
86
|
+
Pgでは任意でRubyと素のCコードにある結果の値やクエリ引数の型変換ができます。
|
87
|
+
こうすることでデータベースとのデータの往来を加速させられます。
|
88
|
+
なぜなら文字列のアロケーションが減り、(比較的遅い)Rubyのコードでの変換部分が省かれるからです。
|
88
89
|
|
89
90
|
とても基本的な型変換は次のようにできます。
|
90
91
|
```ruby
|
@@ -103,9 +104,13 @@ PgにはおまけとしてRubyとネイティブCコードにある結果の値
|
|
103
104
|
|
104
105
|
### エンコーダーとデコーダー (ext/pg_*coder.c, lib/pg/*coder.rb)
|
105
106
|
|
106
|
-
こちらはより低層で、DBMSへ転送するためにRuby
|
107
|
+
こちらはより低層で、DBMSへ転送するためにRubyのオブジェクトを変換するエンコーディングクラスと、取得してきたデータをRubyのオブジェクトに変換し戻すデコーディングクラスが含まれています。
|
108
|
+
クラスはそれぞれの形式によって名前空間 PG::TextEncoder, PG::TextDecoder, PG::BinaryEncoder, そして
|
109
|
+
PG::BinaryDecoder に分かれています。
|
107
110
|
|
108
|
-
エンコーダーないしデコーダーオブジェクトにOID
|
111
|
+
エンコーダーないしデコーダーオブジェクトにOIDデータ型や形式コード(テキストないしバイナリ)や任意で名前を割り当てることができます。
|
112
|
+
要素のエンコーダーないしデコーダーを割り当てることによって複合型を構築することもできます。
|
113
|
+
PG::Coder オブジェクトは PG::TypeMap をセットアップしたり、その代わりに単一の値と文字列表現とを相互に変換したりするのに使えます。
|
109
114
|
|
110
115
|
ruby-pgでは以下のPostgreSQLカラム型に対応しています(TE = Text Encoder、TD = Text Decoder、BE =
|
111
116
|
Binary Encoder、BD = Binary Decoder)。
|
@@ -115,10 +120,12 @@ Binary Encoder、BD = Binary Decoder)。
|
|
115
120
|
💡
|
116
121
|
リンクがないでしょうか。[こちら](https://deveiate.org/code/pg/README_ja_md.html#label-E5-9E-8B-E5-A4-89-E6-8F-9B)を代わりに見てください
|
117
122
|
💡
|
118
|
-
|
119
|
-
|
123
|
+
* BE:
|
124
|
+
[Int2](rdoc-ref:PG::BinaryEncoder::Int2)、[Int4](rdoc-ref:PG::BinaryEncoder::Int4)、[Int8](rdoc-ref:PG::BinaryEncoder::Int8)
|
120
125
|
* Float:
|
121
126
|
[TE](rdoc-ref:PG::TextEncoder::Float)、[TD](rdoc-ref:PG::TextDecoder::Float)、[BD](rdoc-ref:PG::BinaryDecoder::Float)
|
127
|
+
* BE: [Float4](rdoc-ref:PG::BinaryEncoder::Float4),
|
128
|
+
[Float8](rdoc-ref:PG::BinaryEncoder::Float8)
|
122
129
|
* Numeric:
|
123
130
|
[TE](rdoc-ref:PG::TextEncoder::Numeric)、[TD](rdoc-ref:PG::TextDecoder::Numeric)
|
124
131
|
* Boolean:
|
@@ -130,14 +137,15 @@ Binary Encoder、BD = Binary Decoder)。
|
|
130
137
|
* Base64:
|
131
138
|
[TE](rdoc-ref:PG::TextEncoder::ToBase64)、[TD](rdoc-ref:PG::TextDecoder::FromBase64)、[BE](rdoc-ref:PG::BinaryEncoder::FromBase64)、[BD](rdoc-ref:PG::BinaryDecoder::ToBase64)
|
132
139
|
* Timestamp:
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
*
|
140
|
-
|
140
|
+
* TE:
|
141
|
+
[現地時間](rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone)、[UTC](rdoc-ref:PG::TextEncoder::TimestampUtc)、[タイムゾーン付き](rdoc-ref:PG::TextEncoder::TimestampWithTimeZone)
|
142
|
+
* TD:
|
143
|
+
[現地時間](rdoc-ref:PG::TextDecoder::TimestampLocal)、[UTC](rdoc-ref:PG::TextDecoder::TimestampUtc)、[UTCから現地時間へ](rdoc-ref:PG::TextDecoder::TimestampUtcToLocal)
|
144
|
+
* BE:
|
145
|
+
[現地時間](rdoc-ref:PG::BinaryEncoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryEncoder::TimestampUtc)
|
146
|
+
* BD:
|
147
|
+
[現地時間](rdoc-ref:PG::BinaryDecoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryDecoder::TimestampUtc)、[UTCから現地時間へ](rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal)
|
148
|
+
* 日付:[TE](rdoc-ref:PG::TextEncoder::Date)、[TD](rdoc-ref:PG::TextDecoder::Date)、[BE](rdoc-ref:PG::BinaryEncoder::Date)、[BD](rdoc-ref:PG::BinaryDecoder::Date)
|
141
149
|
* JSONとJSONB:
|
142
150
|
[TE](rdoc-ref:PG::TextEncoder::JSON)、[TD](rdoc-ref:PG::TextDecoder::JSON)
|
143
151
|
* Inet:
|
@@ -146,18 +154,25 @@ Binary Encoder、BD = Binary Decoder)。
|
|
146
154
|
[TE](rdoc-ref:PG::TextEncoder::Array)、[TD](rdoc-ref:PG::TextDecoder::Array)
|
147
155
|
* 複合型(「行」や「レコード」などとも言います):[TE](rdoc-ref:PG::TextEncoder::Record)、[TD](rdoc-ref:PG::TextDecoder::Record)
|
148
156
|
|
149
|
-
|
157
|
+
カラム型として使われていませんが、以下のテキスト形式とバイナリ形式もエンコードできます。
|
150
158
|
|
151
|
-
* COPYの入出力データ:[TE](rdoc-ref:PG::TextEncoder::CopyRow)、[TD](rdoc-ref:PG::TextDecoder::CopyRow)
|
159
|
+
* COPYの入出力データ:[TE](rdoc-ref:PG::TextEncoder::CopyRow)、[TD](rdoc-ref:PG::TextDecoder::CopyRow),
|
160
|
+
[BE](rdoc-ref:PG::BinaryEncoder::CopyRow),
|
161
|
+
[BD](rdoc-ref:PG::BinaryDecoder::CopyRow)
|
152
162
|
* SQL文字列に挿入するリテラル:[TE](rdoc-ref:PG::TextEncoder::QuotedLiteral)
|
153
163
|
* SQLの識別子:
|
154
164
|
[TE](rdoc-ref:PG::TextEncoder::Identifier)、[TD](rdoc-ref:PG::TextDecoder::Identifier)
|
155
165
|
|
156
|
-
### PG::TypeMapとその派生 (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
166
|
+
### PG::TypeMap とその派生 (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
157
167
|
|
158
|
-
TypeMap
|
168
|
+
TypeMapはエンコーダーまたはデコーダーのどちらによってどの値を変換するかを定義します。
|
169
|
+
様々な型の対応付け戦略があるので、このクラスにはいくつかの派生が実装されています。
|
170
|
+
型変換の特有の需要に合わせてそれらの派生から選んで調整を加えることができます。
|
171
|
+
既定の型の対応付けは PG::TypeMapAllStrings です。
|
159
172
|
|
160
|
-
|
173
|
+
型の対応付けは、結果の集合それぞれに対し、接続毎ないしクエリ毎に割り当てることができます。
|
174
|
+
型の対応付けはCOPYの入出力データストリーミングでも使うことができます。
|
175
|
+
PG::Connection#copy_data を参照してください。
|
161
176
|
|
162
177
|
以下の基底となる型の対応付けが使えます。
|
163
178
|
|
@@ -167,19 +182,21 @@ TypeMapはエンコーダーまたはデコーダーのどちらによってど
|
|
167
182
|
* PG::TypeMapByOid - PostgreSQLのOIDデータ型によってデコーダーを選択します
|
168
183
|
* PG::TypeMapInRuby - Rubyで独自の型の対応付けを定義します
|
169
184
|
|
170
|
-
以下の型の対応付けはPG::BasicTypeRegistry由来の型の対応付けが入った状態になっています。
|
185
|
+
以下の型の対応付けは PG::BasicTypeRegistry 由来の型の対応付けが入った状態になっています。
|
171
186
|
|
172
|
-
* PG::BasicTypeMapForResults -
|
173
|
-
|
174
|
-
* PG::BasicTypeMapBasedOnResult -
|
175
|
-
|
176
|
-
* PG::BasicTypeMapForQueries -
|
177
|
-
|
187
|
+
* PG::BasicTypeMapForResults - PG::TypeMapByOid
|
188
|
+
によくあるPostgreSQLカラム型用にデコーダーが入った状態になっています
|
189
|
+
* PG::BasicTypeMapBasedOnResult - PG::TypeMapByOid
|
190
|
+
によくあるPostgreSQLカラム型用のエンコーダーが入った状態になっています
|
191
|
+
* PG::BasicTypeMapForQueries - PG::TypeMapByClass
|
192
|
+
によくあるRubyの値クラス用にエンコーダーが入った状態になっています
|
178
193
|
|
179
194
|
|
180
195
|
## スレッド対応
|
181
196
|
|
182
|
-
PGには個々のスレッドが別々のPG::Connection
|
197
|
+
PGには個々のスレッドが別々の PG::Connection オブジェクトを同時に使えるという点でスレッド安全性があります。
|
198
|
+
しかし1つ以上のスレッドから同時にPgのオブジェクトにアクセスすると安全ではありません。
|
199
|
+
そのため必ず、毎回新しいスレッドを作るときに新しいデータベースサーバー接続を開くか、スレッド安全性のある方法で接続を管理するActiveRecordのようなラッパーライブラリを使うようにしてください。
|
183
200
|
|
184
201
|
以下のようなメッセージが標準エラー出力に表示された場合、恐らく複数のスレッドが1つの接続を使っています。
|
185
202
|
|
@@ -192,13 +209,30 @@ PGには個々のスレッドが別々のPG::Connectionオブジェクトを同
|
|
192
209
|
|
193
210
|
## Fiber IOスケジューラー対応
|
194
211
|
|
195
|
-
PgはRuby-3.0で導入された`Fiber.scheduler
|
212
|
+
pg-1.3.0以降で、PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応しています。
|
213
|
+
Windowsでは、`Fiber.scheduler`対応はRuby-3.1以降で使えます。
|
214
|
+
`Fiber.scheduler`が走らせているスレッドに登録されている場合、起こりうる全てのブロッキングIO操作はそのスケジューラーを経由します。
|
215
|
+
同期的であったりブロックしたりするメソッド呼び出しについてもpgが内部的に非同期のlibpqインターフェースを使っているのはそれが理由です。
|
216
|
+
またlibpqの組み込み関数に代えてRubyのDNS解決を使っています。
|
196
217
|
|
197
|
-
内部的にPgは常にlibpq
|
218
|
+
内部的にPgは常にlibpqのノンブロッキング接続モードを使います。
|
219
|
+
それからブロッキングモードで走っているように振舞いますが、もし`Fiber.scheduler`が登録されていれば全てのブロッキングIOはそのスケジューラーを通じてRubyで制御されます。
|
220
|
+
`PG::Connection.setnonblocking(true)`が呼ばれたらノンブロッキング状態が有効になったままになりますが、それ以降のブロッキング状態の制御が無効になるので、呼び出しているプログラムはブロッキング状態を自力で制御しなければなりません。
|
198
221
|
|
199
222
|
この規則の1つの例外には、`PG::Connection#lo_create`や外部ライブラリを使う認証メソッド(GSSAPI認証など)のような、大きめのオブジェクト用のメソッドがあります。これらは`Fiber.scheduler`と互換性がないため、ブロッキング状態は登録されたIOスケジューラに渡されません。つまり操作は適切に実行されますが、IO待ち状態に別のIOを扱うFiberから使用を切り替えてくることができなくなります。
|
200
223
|
|
201
224
|
|
225
|
+
## Ractor対応
|
226
|
+
|
227
|
+
pg-1.5.0以降で、PgはRuby-3.0で導入されたRactorと完全な互換性があります。
|
228
|
+
型エンコーダーないしデコーダー、及び型の対応付けが`Ractor.make_shareable`により凍結されている場合、これらをractor間で共有できます。
|
229
|
+
また凍結された PG::Result と PG::Tuple オブジェクトも共有できます。
|
230
|
+
少なくとも全ての凍結されたオブジェクト(ただし PG::Connection
|
231
|
+
を除く)はPostgreSQLサーバーとのやり取りをしたり取得されたデータを読むのに使えます。
|
232
|
+
|
233
|
+
PG::Connection は共有できません。個々の接続を確立するために、それぞれのRactor内で作られなければなりません。
|
234
|
+
|
235
|
+
|
202
236
|
## 貢献
|
203
237
|
|
204
238
|
バグを報告したり機能を提案したりGitでソースをチェックアウトしたりするには[プロジェクトページをご確認ください](https://github.com/ged/ruby-pg)。
|
@@ -207,7 +241,7 @@ PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応していま
|
|
207
241
|
|
208
242
|
$ bundle install
|
209
243
|
|
210
|
-
|
244
|
+
拡張ファイル、パッケージファイル、テストデータベースを一掃するには、このコマンドを走らせてください。PostgreSQLのバージョンも切り替わります。
|
211
245
|
|
212
246
|
$ rake clean
|
213
247
|
|
@@ -215,13 +249,13 @@ PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応していま
|
|
215
249
|
|
216
250
|
$ rake compile
|
217
251
|
|
218
|
-
|
252
|
+
`pg_config --bindir`が指すPostgreSQLのバージョンでテストやスペックを走らせるには次のようにします。
|
219
253
|
|
220
|
-
$
|
254
|
+
$ rake test
|
221
255
|
|
222
|
-
|
256
|
+
あるいは特定のPostgreSQLのバージョンで、ファイル中の行番号を使って特定のテストを走らせるには次のようにします。
|
223
257
|
|
224
|
-
$ PATH
|
258
|
+
$ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455
|
225
259
|
|
226
260
|
APIドキュメントを生成するには次のようにします。
|
227
261
|
|
@@ -261,6 +295,6 @@ Portions copyright LAIKA, Inc.
|
|
261
295
|
|
262
296
|
## 謝辞
|
263
297
|
|
264
|
-
長年にわたって貢献してくださった方々についてはContributors.rdocを参照してください。
|
298
|
+
長年にわたって貢献してくださった方々については Contributors.rdoc を参照してください。
|
265
299
|
|
266
300
|
ruby-listとruby-devメーリングリストの方々に感謝します。またPostgreSQLを開発された方々へも謝意を表します。
|