cipherstash-pg 1.0.0.beta.1-arm64-darwin-22 → 1.0.0.beta.3-arm64-darwin-22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +137 -0
- data/.gitignore +19 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +45 -0
- data/{History.rdoc → History.md} +168 -153
- data/README.ja.md +266 -0
- data/README.md +272 -0
- data/Rakefile +65 -104
- data/Rakefile.cross +298 -0
- data/certs/larskanis-2023.pem +24 -0
- data/cipherstash-pg.gemspec +0 -0
- data/lib/2.7/pg_ext.bundle +0 -0
- data/lib/3.0/pg_ext.bundle +0 -0
- data/lib/3.1/pg_ext.bundle +0 -0
- data/lib/3.2/pg_ext.bundle +0 -0
- data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
- data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
- data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
- data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
- data/lib/cipherstash-pg/binary_decoder.rb +21 -0
- data/lib/cipherstash-pg/coder.rb +82 -0
- data/lib/cipherstash-pg/connection.rb +467 -0
- data/lib/cipherstash-pg/constants.rb +3 -0
- data/lib/cipherstash-pg/exceptions.rb +19 -0
- data/lib/cipherstash-pg/result.rb +22 -0
- data/lib/cipherstash-pg/text_decoder.rb +43 -0
- data/lib/cipherstash-pg/text_encoder.rb +67 -0
- data/lib/cipherstash-pg/tuple.rb +24 -0
- data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
- data/lib/cipherstash-pg/version.rb +3 -0
- data/lib/cipherstash-pg.rb +56 -11
- data/lib/libpq.5.dylib +0 -0
- data/misc/openssl-pg-segfault.rb +15 -25
- data/misc/postgres/Rakefile +13 -20
- data/misc/postgres/lib/postgres.rb +10 -14
- data/misc/ruby-pg/Rakefile +13 -20
- data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
- data/rakelib/task_extension.rb +17 -31
- data/sample/array_insert.rb +7 -20
- data/sample/async_api.rb +54 -96
- data/sample/async_copyto.rb +20 -35
- data/sample/async_mixed.rb +22 -50
- data/sample/check_conn.rb +8 -20
- data/sample/copydata.rb +18 -68
- data/sample/copyfrom.rb +26 -78
- data/sample/copyto.rb +10 -16
- data/sample/cursor.rb +9 -19
- data/sample/disk_usage_report.rb +89 -174
- data/sample/issue-119.rb +45 -93
- data/sample/losample.rb +48 -66
- data/sample/minimal-testcase.rb +6 -17
- data/sample/notify_wait.rb +21 -67
- data/sample/pg_statistics.rb +100 -281
- data/sample/replication_monitor.rb +119 -218
- data/sample/test_binary_values.rb +14 -30
- data/sample/wal_shipper.rb +199 -431
- data/sample/warehouse_partitions.rb +157 -307
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +875 -0
- data/translation/po/ja.po +868 -0
- data/translation/po4a.cfg +9 -0
- metadata +50 -30
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -233
- data/lib/pg/basic_type_map_based_on_result.rb +0 -47
- data/lib/pg/basic_type_map_for_queries.rb +0 -193
- data/lib/pg/basic_type_map_for_results.rb +0 -81
- data/lib/pg/basic_type_registry.rb +0 -301
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/coder.rb +0 -104
- data/lib/pg/connection.rb +0 -878
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/exceptions.rb +0 -18
- data/lib/pg/result.rb +0 -43
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/lib/pg/tuple.rb +0 -30
- data/lib/pg/type_map_by_column.rb +0 -16
- data/lib/pg/version.rb +0 -4
- data/lib/pg.rb +0 -55
- data/vendor/database-extensions/install.sql +0 -317
- data/vendor/database-extensions/uninstall.sql +0 -20
metadata
CHANGED
@@ -1,60 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cipherstash-pg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.3
|
5
5
|
platform: arm64-darwin-22
|
6
6
|
authors:
|
7
|
-
- CipherStash
|
7
|
+
- CipherStash Engineers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: CipherStashPG is the Ruby interface to CipherStash-enhanced PostgresQL,
|
14
|
+
based on PG. Known to work on Postgres 14+ (might work on older version)
|
15
15
|
email:
|
16
16
|
- engineers@cipherstash.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- "./.appveyor.yml"
|
22
|
+
- "./.gems"
|
23
|
+
- "./.gemtest"
|
24
|
+
- "./.github/workflows/binary-gems.yml"
|
25
|
+
- "./.github/workflows/source-gem.yml"
|
26
|
+
- "./.gitignore"
|
27
|
+
- "./.hgsigs"
|
28
|
+
- "./.hgtags"
|
29
|
+
- "./.irbrc"
|
30
|
+
- "./.pryrc"
|
31
|
+
- "./.tm_properties"
|
32
|
+
- "./.travis.yml"
|
21
33
|
- "./BSDL"
|
22
34
|
- "./Contributors.rdoc"
|
23
35
|
- "./Gemfile"
|
24
|
-
- "./
|
36
|
+
- "./Gemfile.lock"
|
37
|
+
- "./History.md"
|
25
38
|
- "./LICENSE"
|
26
39
|
- "./Manifest.txt"
|
27
40
|
- "./POSTGRES"
|
28
41
|
- "./README-OS_X.rdoc"
|
29
42
|
- "./README-Windows.rdoc"
|
30
|
-
- "./README.ja.
|
31
|
-
- "./README.
|
43
|
+
- "./README.ja.md"
|
44
|
+
- "./README.md"
|
32
45
|
- "./Rakefile"
|
46
|
+
- "./Rakefile.cross"
|
33
47
|
- "./certs/ged.pem"
|
34
48
|
- "./certs/larskanis-2022.pem"
|
49
|
+
- "./certs/larskanis-2023.pem"
|
35
50
|
- "./cipherstash-pg.gemspec"
|
36
51
|
- "./lib/2.7/pg_ext.bundle"
|
37
52
|
- "./lib/3.0/pg_ext.bundle"
|
38
53
|
- "./lib/3.1/pg_ext.bundle"
|
39
54
|
- "./lib/3.2/pg_ext.bundle"
|
40
55
|
- "./lib/cipherstash-pg.rb"
|
56
|
+
- "./lib/cipherstash-pg/basic_type_map_based_on_result.rb"
|
57
|
+
- "./lib/cipherstash-pg/basic_type_map_for_queries.rb"
|
58
|
+
- "./lib/cipherstash-pg/basic_type_map_for_results.rb"
|
59
|
+
- "./lib/cipherstash-pg/basic_type_registry.rb"
|
60
|
+
- "./lib/cipherstash-pg/binary_decoder.rb"
|
61
|
+
- "./lib/cipherstash-pg/coder.rb"
|
62
|
+
- "./lib/cipherstash-pg/connection.rb"
|
63
|
+
- "./lib/cipherstash-pg/constants.rb"
|
64
|
+
- "./lib/cipherstash-pg/exceptions.rb"
|
65
|
+
- "./lib/cipherstash-pg/result.rb"
|
66
|
+
- "./lib/cipherstash-pg/text_decoder.rb"
|
67
|
+
- "./lib/cipherstash-pg/text_encoder.rb"
|
68
|
+
- "./lib/cipherstash-pg/tuple.rb"
|
69
|
+
- "./lib/cipherstash-pg/type_map_by_column.rb"
|
70
|
+
- "./lib/cipherstash-pg/version.rb"
|
41
71
|
- "./lib/libpq.5.dylib"
|
42
|
-
- "./lib/pg.rb"
|
43
|
-
- "./lib/pg/basic_type_map_based_on_result.rb"
|
44
|
-
- "./lib/pg/basic_type_map_for_queries.rb"
|
45
|
-
- "./lib/pg/basic_type_map_for_results.rb"
|
46
|
-
- "./lib/pg/basic_type_registry.rb"
|
47
|
-
- "./lib/pg/binary_decoder.rb"
|
48
|
-
- "./lib/pg/coder.rb"
|
49
|
-
- "./lib/pg/connection.rb"
|
50
|
-
- "./lib/pg/constants.rb"
|
51
|
-
- "./lib/pg/exceptions.rb"
|
52
|
-
- "./lib/pg/result.rb"
|
53
|
-
- "./lib/pg/text_decoder.rb"
|
54
|
-
- "./lib/pg/text_encoder.rb"
|
55
|
-
- "./lib/pg/tuple.rb"
|
56
|
-
- "./lib/pg/type_map_by_column.rb"
|
57
|
-
- "./lib/pg/version.rb"
|
58
72
|
- "./misc/openssl-pg-segfault.rb"
|
59
73
|
- "./misc/postgres/History.txt"
|
60
74
|
- "./misc/postgres/Manifest.txt"
|
@@ -86,17 +100,23 @@ files:
|
|
86
100
|
- "./sample/test_binary_values.rb"
|
87
101
|
- "./sample/wal_shipper.rb"
|
88
102
|
- "./sample/warehouse_partitions.rb"
|
89
|
-
- "./
|
90
|
-
- "./
|
103
|
+
- "./translation/.po4a-version"
|
104
|
+
- "./translation/po/all.pot"
|
105
|
+
- "./translation/po/ja.po"
|
106
|
+
- "./translation/po4a.cfg"
|
91
107
|
homepage: https://github.com/cipherstash/cipherstash-pg
|
92
108
|
licenses:
|
93
109
|
- BSD-2-Clause
|
94
110
|
metadata:
|
95
111
|
homepage_uri: https://github.com/cipherstash/cipherstash-pg
|
96
112
|
source_code_uri: https://github.com/cipherstash/cipherstash-pg
|
97
|
-
|
113
|
+
derived_from_pg_gem_version: 1.4.6
|
98
114
|
post_install_message:
|
99
|
-
rdoc_options:
|
115
|
+
rdoc_options:
|
116
|
+
- "--main"
|
117
|
+
- README.md
|
118
|
+
- "--title"
|
119
|
+
- 'CipherStashPG: The Ruby PostgreSQL Driver for CipherStash-enhanced PostgreSQL'
|
100
120
|
require_paths:
|
101
121
|
- lib
|
102
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -113,6 +133,6 @@ requirements: []
|
|
113
133
|
rubygems_version: 3.4.6
|
114
134
|
signing_key:
|
115
135
|
specification_version: 4
|
116
|
-
summary:
|
117
|
-
|
136
|
+
summary: CipherStashPG is the Ruby interface to CipherStash-enhanced PostgresQL, based
|
137
|
+
on PG
|
118
138
|
test_files: []
|
data/README.ja.rdoc
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
= pg
|
2
|
-
|
3
|
-
home :: https://github.com/ged/ruby-pg
|
4
|
-
docs :: http://deveiate.org/code/pg
|
5
|
-
|
6
|
-
|
7
|
-
== Description
|
8
|
-
|
9
|
-
This file needs a translation of the English README. Pull requests, patches, or
|
10
|
-
volunteers gladly accepted.
|
11
|
-
|
12
|
-
Until such time, please accept my sincere apologies for not knowing Japanese.
|
13
|
-
|
data/README.rdoc
DELETED
@@ -1,233 +0,0 @@
|
|
1
|
-
= pg
|
2
|
-
|
3
|
-
home :: https://github.com/ged/ruby-pg
|
4
|
-
docs :: http://deveiate.org/code/pg
|
5
|
-
clog :: link:/History.rdoc
|
6
|
-
|
7
|
-
{<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/ged/ruby-pg">}[https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
|
8
|
-
|
9
|
-
|
10
|
-
== Description
|
11
|
-
|
12
|
-
Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
|
13
|
-
|
14
|
-
It works with {PostgreSQL 9.3 and later}[http://www.postgresql.org/support/versioning/].
|
15
|
-
|
16
|
-
A small example usage:
|
17
|
-
|
18
|
-
#!/usr/bin/env ruby
|
19
|
-
|
20
|
-
require 'pg'
|
21
|
-
|
22
|
-
# Output a table of current connections to the DB
|
23
|
-
conn = PG.connect( dbname: 'sales' )
|
24
|
-
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
|
25
|
-
puts " PID | User | Query"
|
26
|
-
result.each do |row|
|
27
|
-
puts " %7d | %-16s | %s " %
|
28
|
-
row.values_at('pid', 'usename', 'query')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
== Build Status
|
33
|
-
|
34
|
-
{<img src="https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml/badge.svg?branch=master" alt="Build Status Github Actions" />}[https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml]
|
35
|
-
{<img src="https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg-9j8l3]
|
36
|
-
{<img src="https://app.travis-ci.com/larskanis/ruby-pg.svg?branch=master" alt="Build Status" />}[https://app.travis-ci.com/larskanis/ruby-pg]
|
37
|
-
|
38
|
-
== Requirements
|
39
|
-
|
40
|
-
* Ruby 2.4 or newer
|
41
|
-
* PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
|
42
|
-
|
43
|
-
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
44
|
-
not regularly tested.
|
45
|
-
|
46
|
-
|
47
|
-
== Versioning
|
48
|
-
|
49
|
-
We tag and release gems according to the {Semantic Versioning}[http://semver.org/] principle.
|
50
|
-
|
51
|
-
As a result of this policy, you can (and should) specify a dependency on this gem using the {Pessimistic Version Constraint}[http://guides.rubygems.org/patterns/#pessimistic-version-constraint] with two digits of precision.
|
52
|
-
|
53
|
-
For example:
|
54
|
-
|
55
|
-
spec.add_dependency 'pg', '~> 1.0'
|
56
|
-
|
57
|
-
|
58
|
-
== How To Install
|
59
|
-
|
60
|
-
Install via RubyGems:
|
61
|
-
|
62
|
-
gem install pg
|
63
|
-
|
64
|
-
You may need to specify the path to the 'pg_config' program installed with
|
65
|
-
Postgres:
|
66
|
-
|
67
|
-
gem install pg -- --with-pg-config=<path to pg_config>
|
68
|
-
|
69
|
-
If you're installing via Bundler, you can provide compile hints like so:
|
70
|
-
|
71
|
-
bundle config build.pg --with-pg-config=<path to pg_config>
|
72
|
-
|
73
|
-
See README-OS_X.rdoc for more information about installing under MacOS X, and
|
74
|
-
README-Windows.rdoc for Windows build/installation instructions.
|
75
|
-
|
76
|
-
There's also {a Google+ group}[http://goo.gl/TFy1U] and a
|
77
|
-
{mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
|
78
|
-
want to chat about something.
|
79
|
-
|
80
|
-
If you want to install as a signed gem, the public certs of the gem signers
|
81
|
-
can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
|
82
|
-
of the repository.
|
83
|
-
|
84
|
-
|
85
|
-
== Type Casts
|
86
|
-
|
87
|
-
Pg can optionally type cast result values and query parameters in Ruby or
|
88
|
-
native C code. This can speed up data transfers to and from the database,
|
89
|
-
because String allocations are reduced and conversions in (slower) Ruby code
|
90
|
-
can be omitted.
|
91
|
-
|
92
|
-
Very basic type casting can be enabled by:
|
93
|
-
|
94
|
-
conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
|
95
|
-
# ... this works for result value mapping:
|
96
|
-
conn.exec("select 1, now(), '{2,3}'::int[]").values
|
97
|
-
# => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
|
98
|
-
|
99
|
-
conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
|
100
|
-
# ... and this for param value mapping:
|
101
|
-
conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
|
102
|
-
# => [["1", "1.2300000000000000E+00", "{2,3}"]]
|
103
|
-
|
104
|
-
But Pg's type casting is highly customizable. That's why it's divided into
|
105
|
-
2 layers:
|
106
|
-
|
107
|
-
=== Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
|
108
|
-
|
109
|
-
This is the lower layer, containing encoding classes that convert Ruby
|
110
|
-
objects for transmission to the DBMS and decoding classes to convert
|
111
|
-
received data back to Ruby objects. The classes are namespaced according
|
112
|
-
to their format and direction in PG::TextEncoder, PG::TextDecoder,
|
113
|
-
PG::BinaryEncoder and PG::BinaryDecoder.
|
114
|
-
|
115
|
-
It is possible to assign a type OID, format code (text or binary) and
|
116
|
-
optionally a name to an encoder or decoder object. It's also possible
|
117
|
-
to build composite types by assigning an element encoder/decoder.
|
118
|
-
PG::Coder objects can be used to set up a PG::TypeMap or alternatively
|
119
|
-
to convert single values to/from their string representation.
|
120
|
-
|
121
|
-
The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
|
122
|
-
* Integer: {TE}[rdoc-ref:PG::TextEncoder::Integer], {TD}[rdoc-ref:PG::TextDecoder::Integer], {BD}[rdoc-ref:PG::BinaryDecoder::Integer] 💡 No links? Switch to {here}[https://deveiate.org/code/pg/README_rdoc.html#label-Type+Casts] 💡
|
123
|
-
* BE: {Int2}[rdoc-ref:PG::BinaryEncoder::Int2], {Int4}[rdoc-ref:PG::BinaryEncoder::Int4], {Int8}[rdoc-ref:PG::BinaryEncoder::Int8]
|
124
|
-
* Float: {TE}[rdoc-ref:PG::TextEncoder::Float], {TD}[rdoc-ref:PG::TextDecoder::Float], {BD}[rdoc-ref:PG::BinaryDecoder::Float]
|
125
|
-
* Numeric: {TE}[rdoc-ref:PG::TextEncoder::Numeric], {TD}[rdoc-ref:PG::TextDecoder::Numeric]
|
126
|
-
* Boolean: {TE}[rdoc-ref:PG::TextEncoder::Boolean], {TD}[rdoc-ref:PG::TextDecoder::Boolean], {BE}[rdoc-ref:PG::BinaryEncoder::Boolean], {BD}[rdoc-ref:PG::BinaryDecoder::Boolean]
|
127
|
-
* String: {TE}[rdoc-ref:PG::TextEncoder::String], {TD}[rdoc-ref:PG::TextDecoder::String], {BE}[rdoc-ref:PG::BinaryEncoder::String], {BD}[rdoc-ref:PG::BinaryDecoder::String]
|
128
|
-
* Bytea: {TE}[rdoc-ref:PG::TextEncoder::Bytea], {TD}[rdoc-ref:PG::TextDecoder::Bytea], {BE}[rdoc-ref:PG::BinaryEncoder::Bytea], {BD}[rdoc-ref:PG::BinaryDecoder::Bytea]
|
129
|
-
* Base64: {TE}[rdoc-ref:PG::TextEncoder::ToBase64], {TD}[rdoc-ref:PG::TextDecoder::FromBase64], {BE}[rdoc-ref:PG::BinaryEncoder::FromBase64], {BD}[rdoc-ref:PG::BinaryDecoder::ToBase64]
|
130
|
-
* Timestamp:
|
131
|
-
* TE: {local}[rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone], {UTC}[rdoc-ref:PG::TextEncoder::TimestampUtc], {with-TZ}[rdoc-ref:PG::TextEncoder::TimestampWithTimeZone]
|
132
|
-
* TD: {local}[rdoc-ref:PG::TextDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::TextDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::TextDecoder::TimestampUtcToLocal]
|
133
|
-
* BD: {local}[rdoc-ref:PG::BinaryDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::BinaryDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal]
|
134
|
-
* Date: {TE}[rdoc-ref:PG::TextEncoder::Date], {TD}[rdoc-ref:PG::TextDecoder::Date]
|
135
|
-
* JSON and JSONB: {TE}[rdoc-ref:PG::TextEncoder::JSON], {TD}[rdoc-ref:PG::TextDecoder::JSON]
|
136
|
-
* Inet: {TE}[rdoc-ref:PG::TextEncoder::Inet], {TD}[rdoc-ref:PG::TextDecoder::Inet]
|
137
|
-
* Array: {TE}[rdoc-ref:PG::TextEncoder::Array], {TD}[rdoc-ref:PG::TextDecoder::Array]
|
138
|
-
* Composite Type (also called "Row" or "Record"): {TE}[rdoc-ref:PG::TextEncoder::Record], {TD}[rdoc-ref:PG::TextDecoder::Record]
|
139
|
-
|
140
|
-
The following text formats can also be encoded although they are not used as column type:
|
141
|
-
* COPY input and output data: {TE}[rdoc-ref:PG::TextEncoder::CopyRow], {TD}[rdoc-ref:PG::TextDecoder::CopyRow]
|
142
|
-
* Literal for insertion into SQL string: {TE}[rdoc-ref:PG::TextEncoder::QuotedLiteral]
|
143
|
-
* SQL-Identifier: {TE}[rdoc-ref:PG::TextEncoder::Identifier], {TD}[rdoc-ref:PG::TextDecoder::Identifier]
|
144
|
-
|
145
|
-
=== PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
146
|
-
|
147
|
-
A TypeMap defines which value will be converted by which encoder/decoder.
|
148
|
-
There are different type map strategies, implemented by several derivations
|
149
|
-
of this class. They can be chosen and configured according to the particular
|
150
|
-
needs for type casting. The default type map is PG::TypeMapAllStrings.
|
151
|
-
|
152
|
-
A type map can be assigned per connection or per query respectively per
|
153
|
-
result set. Type maps can also be used for COPY in and out data streaming.
|
154
|
-
See PG::Connection#copy_data .
|
155
|
-
|
156
|
-
The following base type maps are available:
|
157
|
-
* PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
|
158
|
-
* PG::TypeMapByClass - selects encoder based on the class of the value to be sent
|
159
|
-
* PG::TypeMapByColumn - selects encoder and decoder by column order
|
160
|
-
* PG::TypeMapByOid - selects decoder by PostgreSQL type OID
|
161
|
-
* PG::TypeMapInRuby - define a custom type map in ruby
|
162
|
-
|
163
|
-
The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
|
164
|
-
* PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
|
165
|
-
* PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
|
166
|
-
* PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
|
167
|
-
|
168
|
-
|
169
|
-
== Contributing
|
170
|
-
|
171
|
-
To report bugs, suggest features, or check out the source with Git,
|
172
|
-
{check out the project page}[https://github.com/ged/ruby-pg].
|
173
|
-
|
174
|
-
After checking out the source, install all dependencies:
|
175
|
-
|
176
|
-
$ bundle install
|
177
|
-
|
178
|
-
Cleanup extension files, packaging files, test databases:
|
179
|
-
|
180
|
-
$ rake clean
|
181
|
-
|
182
|
-
Compile extension:
|
183
|
-
|
184
|
-
$ rake compile
|
185
|
-
|
186
|
-
Run tests/specs with PostgreSQL tools like `initdb` in the path:
|
187
|
-
|
188
|
-
$ PATH=$PATH:/usr/lib/postgresql/14/bin rake test
|
189
|
-
|
190
|
-
Or run a specific test with the line number:
|
191
|
-
|
192
|
-
$ PATH=$PATH:/usr/lib/postgresql/14/bin rspec -Ilib -fd spec/pg/connection_spec.rb:455
|
193
|
-
|
194
|
-
Generate the API documentation:
|
195
|
-
|
196
|
-
$ rake docs
|
197
|
-
|
198
|
-
Make sure, that all bugs and new features are verified by tests.
|
199
|
-
|
200
|
-
The current maintainers are Michael Granger <ged@FaerieMUD.org> and
|
201
|
-
Lars Kanis <lars@greiz-reinsdorf.de>.
|
202
|
-
|
203
|
-
|
204
|
-
== Copying
|
205
|
-
|
206
|
-
Copyright (c) 1997-2022 by the authors.
|
207
|
-
|
208
|
-
* Jeff Davis <ruby-pg@j-davis.com>
|
209
|
-
* Guy Decoux (ts) <decoux@moulon.inra.fr>
|
210
|
-
* Michael Granger <ged@FaerieMUD.org>
|
211
|
-
* Lars Kanis <lars@greiz-reinsdorf.de>
|
212
|
-
* Dave Lee
|
213
|
-
* Eiji Matsumoto <usagi@ruby.club.or.jp>
|
214
|
-
* Yukihiro Matsumoto <matz@ruby-lang.org>
|
215
|
-
* Noboru Saitou <noborus@netlab.jp>
|
216
|
-
|
217
|
-
You may redistribute this software under the same terms as Ruby itself; see
|
218
|
-
https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
|
219
|
-
for details.
|
220
|
-
|
221
|
-
Portions of the code are from the PostgreSQL project, and are distributed
|
222
|
-
under the terms of the PostgreSQL license, included in the file POSTGRES.
|
223
|
-
|
224
|
-
Portions copyright LAIKA, Inc.
|
225
|
-
|
226
|
-
|
227
|
-
== Acknowledgments
|
228
|
-
|
229
|
-
See Contributors.rdoc for the many additional fine people that have contributed
|
230
|
-
to this library over the years.
|
231
|
-
|
232
|
-
We are thankful to the people at the ruby-list and ruby-dev mailing lists.
|
233
|
-
And to the people who developed PostgreSQL.
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'pg' unless defined?( PG )
|
5
|
-
|
6
|
-
# Simple set of rules for type casting common PostgreSQL types from Ruby
|
7
|
-
# to PostgreSQL.
|
8
|
-
#
|
9
|
-
# OIDs of supported type casts are not hard-coded in the sources, but are retrieved from the
|
10
|
-
# PostgreSQL's +pg_type+ table in PG::BasicTypeMapBasedOnResult.new .
|
11
|
-
#
|
12
|
-
# This class works equal to PG::BasicTypeMapForResults, but does not define decoders for
|
13
|
-
# the given result OIDs, but encoders. So it can be used to type cast field values based on
|
14
|
-
# the type OID retrieved by a separate SQL query.
|
15
|
-
#
|
16
|
-
# PG::TypeMapByOid#build_column_map(result) can be used to generate a result independent
|
17
|
-
# PG::TypeMapByColumn type map, which can subsequently be used to cast query bind parameters
|
18
|
-
# or #put_copy_data fields.
|
19
|
-
#
|
20
|
-
# Example:
|
21
|
-
# conn.exec( "CREATE TEMP TABLE copytable (t TEXT, i INT, ai INT[])" )
|
22
|
-
#
|
23
|
-
# # Retrieve table OIDs per empty result set.
|
24
|
-
# res = conn.exec( "SELECT * FROM copytable LIMIT 0" )
|
25
|
-
# # Build a type map for common ruby to database type encoders.
|
26
|
-
# btm = PG::BasicTypeMapBasedOnResult.new(conn)
|
27
|
-
# # Build a PG::TypeMapByColumn with encoders suitable for copytable.
|
28
|
-
# tm = btm.build_column_map( res )
|
29
|
-
# row_encoder = PG::TextEncoder::CopyRow.new type_map: tm
|
30
|
-
#
|
31
|
-
# conn.copy_data( "COPY copytable FROM STDIN", row_encoder ) do |res|
|
32
|
-
# conn.put_copy_data ['a', 123, [5,4,3]]
|
33
|
-
# end
|
34
|
-
# This inserts a single row into copytable with type casts from ruby to
|
35
|
-
# database types.
|
36
|
-
class PG::BasicTypeMapBasedOnResult < PG::TypeMapByOid
|
37
|
-
include PG::BasicTypeRegistry::Checker
|
38
|
-
|
39
|
-
def initialize(connection_or_coder_maps, registry: nil)
|
40
|
-
@coder_maps = build_coder_maps(connection_or_coder_maps, registry: registry)
|
41
|
-
|
42
|
-
# Populate TypeMapByOid hash with encoders
|
43
|
-
@coder_maps.each_format(:encoder).flat_map{|f| f.coders }.each do |coder|
|
44
|
-
add_coder(coder)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,193 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'pg' unless defined?( PG )
|
5
|
-
|
6
|
-
# Simple set of rules for type casting common Ruby types to PostgreSQL.
|
7
|
-
#
|
8
|
-
# OIDs of supported type casts are not hard-coded in the sources, but are retrieved from the
|
9
|
-
# PostgreSQL's pg_type table in PG::BasicTypeMapForQueries.new .
|
10
|
-
#
|
11
|
-
# Query params are type casted based on the class of the given value.
|
12
|
-
#
|
13
|
-
# Higher level libraries will most likely not make use of this class, but use their
|
14
|
-
# own derivation of PG::TypeMapByClass or another set of rules to choose suitable
|
15
|
-
# encoders and decoders for the values to be sent.
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
# conn = PG::Connection.new
|
19
|
-
# # Assign a default ruleset for type casts of input and output values.
|
20
|
-
# conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn)
|
21
|
-
# # Execute a query. The Integer param value is typecasted internally by PG::BinaryEncoder::Int8.
|
22
|
-
# # The format of the parameter is set to 0 (text) and the OID of this parameter is set to 20 (int8).
|
23
|
-
# res = conn.exec_params( "SELECT $1", [5] )
|
24
|
-
class PG::BasicTypeMapForQueries < PG::TypeMapByClass
|
25
|
-
# Helper class for submission of binary strings into bytea columns.
|
26
|
-
#
|
27
|
-
# Since PG::BasicTypeMapForQueries chooses the encoder to be used by the class of the submitted value,
|
28
|
-
# it's necessary to send binary strings as BinaryData.
|
29
|
-
# That way they're distinct from text strings.
|
30
|
-
# Please note however that PG::BasicTypeMapForResults delivers bytea columns as plain String
|
31
|
-
# with binary encoding.
|
32
|
-
#
|
33
|
-
# conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn)
|
34
|
-
# conn.exec("CREATE TEMP TABLE test (data bytea)")
|
35
|
-
# bd = PG::BasicTypeMapForQueries::BinaryData.new("ab\xff\0cd")
|
36
|
-
# conn.exec_params("INSERT INTO test (data) VALUES ($1)", [bd])
|
37
|
-
class BinaryData < String
|
38
|
-
end
|
39
|
-
|
40
|
-
class UndefinedEncoder < RuntimeError
|
41
|
-
end
|
42
|
-
|
43
|
-
include PG::BasicTypeRegistry::Checker
|
44
|
-
|
45
|
-
# Create a new type map for query submission
|
46
|
-
#
|
47
|
-
# Options:
|
48
|
-
# * +registry+: Custom type registry, nil for default global registry
|
49
|
-
# * +if_undefined+: Optional +Proc+ object which is called, if no type for an parameter class is not defined in the registry.
|
50
|
-
def initialize(connection_or_coder_maps, registry: nil, if_undefined: nil)
|
51
|
-
@coder_maps = build_coder_maps(connection_or_coder_maps, registry: registry)
|
52
|
-
@array_encoders_by_klass = array_encoders_by_klass
|
53
|
-
@encode_array_as = :array
|
54
|
-
@if_undefined = if_undefined || proc { |oid_name, format|
|
55
|
-
raise UndefinedEncoder, "no encoder defined for type #{oid_name.inspect} format #{format}"
|
56
|
-
}
|
57
|
-
init_encoders
|
58
|
-
end
|
59
|
-
|
60
|
-
# Change the mechanism that is used to encode ruby array values
|
61
|
-
#
|
62
|
-
# Possible values:
|
63
|
-
# * +:array+ : Encode the ruby array as a PostgreSQL array.
|
64
|
-
# The array element type is inferred from the class of the first array element. This is the default.
|
65
|
-
# * +:json+ : Encode the ruby array as a JSON document.
|
66
|
-
# * +:record+ : Encode the ruby array as a composite type row.
|
67
|
-
# * <code>"_type"</code> : Encode the ruby array as a particular PostgreSQL type.
|
68
|
-
# All PostgreSQL array types are supported.
|
69
|
-
# If there's an encoder registered for the elements +type+, it will be used.
|
70
|
-
# Otherwise a string conversion (by +value.to_s+) is done.
|
71
|
-
def encode_array_as=(pg_type)
|
72
|
-
case pg_type
|
73
|
-
when :array
|
74
|
-
when :json
|
75
|
-
when :record
|
76
|
-
when /\A_/
|
77
|
-
else
|
78
|
-
raise ArgumentError, "invalid pg_type #{pg_type.inspect}"
|
79
|
-
end
|
80
|
-
|
81
|
-
@encode_array_as = pg_type
|
82
|
-
|
83
|
-
init_encoders
|
84
|
-
end
|
85
|
-
|
86
|
-
attr_reader :encode_array_as
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def init_encoders
|
91
|
-
coders.each { |kl, c| self[kl] = nil } # Clear type map
|
92
|
-
populate_encoder_list
|
93
|
-
@textarray_encoder = coder_by_name(0, :encoder, '_text')
|
94
|
-
end
|
95
|
-
|
96
|
-
def coder_by_name(format, direction, name)
|
97
|
-
check_format_and_direction(format, direction)
|
98
|
-
@coder_maps.map_for(format, direction).coder_by_name(name)
|
99
|
-
end
|
100
|
-
|
101
|
-
def undefined(name, format)
|
102
|
-
@if_undefined.call(name, format)
|
103
|
-
end
|
104
|
-
|
105
|
-
def populate_encoder_list
|
106
|
-
DEFAULT_TYPE_MAP.each do |klass, selector|
|
107
|
-
if Array === selector
|
108
|
-
format, name, oid_name = selector
|
109
|
-
coder = coder_by_name(format, :encoder, name).dup
|
110
|
-
if coder
|
111
|
-
if oid_name
|
112
|
-
oid_coder = coder_by_name(format, :encoder, oid_name)
|
113
|
-
if oid_coder
|
114
|
-
coder.oid = oid_coder.oid
|
115
|
-
else
|
116
|
-
undefined(oid_name, format)
|
117
|
-
end
|
118
|
-
else
|
119
|
-
coder.oid = 0
|
120
|
-
end
|
121
|
-
self[klass] = coder
|
122
|
-
else
|
123
|
-
undefined(name, format)
|
124
|
-
end
|
125
|
-
else
|
126
|
-
|
127
|
-
case @encode_array_as
|
128
|
-
when :array
|
129
|
-
self[klass] = selector
|
130
|
-
when :json
|
131
|
-
self[klass] = PG::TextEncoder::JSON.new
|
132
|
-
when :record
|
133
|
-
self[klass] = PG::TextEncoder::Record.new type_map: self
|
134
|
-
when /\A_/
|
135
|
-
coder = coder_by_name(0, :encoder, @encode_array_as)
|
136
|
-
if coder
|
137
|
-
self[klass] = coder
|
138
|
-
else
|
139
|
-
undefined(@encode_array_as, format)
|
140
|
-
end
|
141
|
-
else
|
142
|
-
raise ArgumentError, "invalid pg_type #{@encode_array_as.inspect}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def array_encoders_by_klass
|
149
|
-
DEFAULT_ARRAY_TYPE_MAP.inject({}) do |h, (klass, (format, name))|
|
150
|
-
h[klass] = coder_by_name(format, :encoder, name)
|
151
|
-
h
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def get_array_type(value)
|
156
|
-
elem = value
|
157
|
-
while elem.kind_of?(Array)
|
158
|
-
elem = elem.first
|
159
|
-
end
|
160
|
-
@array_encoders_by_klass[elem.class] ||
|
161
|
-
elem.class.ancestors.lazy.map{|ancestor| @array_encoders_by_klass[ancestor] }.find{|a| a } ||
|
162
|
-
@textarray_encoder
|
163
|
-
end
|
164
|
-
|
165
|
-
DEFAULT_TYPE_MAP = {
|
166
|
-
TrueClass => [1, 'bool', 'bool'],
|
167
|
-
FalseClass => [1, 'bool', 'bool'],
|
168
|
-
# We use text format and no type OID for numbers, because setting the OID can lead
|
169
|
-
# to unnecessary type conversions on server side.
|
170
|
-
Integer => [0, 'int8'],
|
171
|
-
Float => [0, 'float8'],
|
172
|
-
BigDecimal => [0, 'numeric'],
|
173
|
-
Time => [0, 'timestamptz'],
|
174
|
-
# We use text format and no type OID for IPAddr, because setting the OID can lead
|
175
|
-
# to unnecessary inet/cidr conversions on the server side.
|
176
|
-
IPAddr => [0, 'inet'],
|
177
|
-
Hash => [0, 'json'],
|
178
|
-
Array => :get_array_type,
|
179
|
-
BinaryData => [1, 'bytea'],
|
180
|
-
}
|
181
|
-
|
182
|
-
DEFAULT_ARRAY_TYPE_MAP = {
|
183
|
-
TrueClass => [0, '_bool'],
|
184
|
-
FalseClass => [0, '_bool'],
|
185
|
-
Integer => [0, '_int8'],
|
186
|
-
String => [0, '_text'],
|
187
|
-
Float => [0, '_float8'],
|
188
|
-
BigDecimal => [0, '_numeric'],
|
189
|
-
Time => [0, '_timestamptz'],
|
190
|
-
IPAddr => [0, '_inet'],
|
191
|
-
}
|
192
|
-
|
193
|
-
end
|