pgoutput-decoder 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +278 -0
- data/lib/pgoutput/decoder/version.rb +7 -0
- data/lib/pgoutput/decoder.rb +10 -0
- data/sig/pgoutput/decoder.rbs +6 -0
- metadata +163 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9ef596cb600c9565a1d4088f34af0877c1dc135bf23e785800ba79cfabb4bc23
|
|
4
|
+
data.tar.gz: d64785d16df4da805dcb358c8193b70e360e4fc07d7afe2e676f4248c1588cb1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: eb5c9be51c3ca6cf6a575f3ef2f8c6eca2e32730a9804f590576c0d53f2daa8e184af4d92c3131e4f3d370b793bd1373fe8e722a6d266f7e02072aa18c666bc0
|
|
7
|
+
data.tar.gz: 669771765199e459020de5a22b87a3d70d4927b1fd5a7a7d59e9159f7944c32304c619920dcd4550711630d143ff20b1444e5ff1ee2d3b8e4b4ec5f19ecf9177
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keneth C. Demanawa
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# pgoutput-decoder
|
|
2
|
+
|
|
3
|
+
A high-level PostgreSQL `pgoutput` logical replication value decoder for Ruby.
|
|
4
|
+
|
|
5
|
+
`pgoutput-decoder` is the companion layer to [`pgoutput-parser`](https://rubygems.org/gems/pgoutput-parser). It accepts immutable protocol messages produced by `pgoutput-parser` and turns tuple payloads into application-friendly Ruby row-change events.
|
|
6
|
+
|
|
7
|
+
It does **not** parse PostgreSQL wire bytes and it does **not** open replication connections. Those concerns belong to lower-level parser and future client layers.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Ruby 3.4+
|
|
14
|
+
- `pgoutput-parser` `~> 0.1`
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
pgoutput-parser
|
|
22
|
+
│
|
|
23
|
+
▼
|
|
24
|
+
Protocol messages
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
pgoutput-decoder
|
|
28
|
+
│
|
|
29
|
+
▼
|
|
30
|
+
Decoded row-change events
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## What This Gem Does
|
|
36
|
+
|
|
37
|
+
- Decodes PostgreSQL OID-backed tuple values
|
|
38
|
+
- Builds Ruby hashes from relation columns and tuple values
|
|
39
|
+
- Tracks relation metadata from `Relation` messages
|
|
40
|
+
- Tracks active transaction context from `Begin` / `Commit` messages
|
|
41
|
+
- Attaches `transaction_id` to DML events
|
|
42
|
+
- Returns immutable, Ractor-shareable event objects
|
|
43
|
+
- Supports custom OID decoders
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## What This Gem Does Not Do
|
|
48
|
+
|
|
49
|
+
This gem intentionally does not:
|
|
50
|
+
|
|
51
|
+
- Parse PostgreSQL `CopyData` bytes
|
|
52
|
+
- Manage replication slots
|
|
53
|
+
- Open replication connections
|
|
54
|
+
- Maintain WAL acknowledgements
|
|
55
|
+
- Reconnect to PostgreSQL
|
|
56
|
+
- Publish events to queues
|
|
57
|
+
- Integrate with ActiveRecord
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
gem "pgoutput-decoder"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bundle install
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Require it with:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
require "pgoutput/decoder"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Quick Start
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
require "pgoutput"
|
|
85
|
+
require "pgoutput/decoder"
|
|
86
|
+
|
|
87
|
+
stream = Pgoutput::RelationTracker.new
|
|
88
|
+
decoder = Pgoutput::Decoder.new
|
|
89
|
+
|
|
90
|
+
protocol_message = stream.process(payload)
|
|
91
|
+
event = decoder.decode(protocol_message)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A `Relation` message updates decoder metadata and returns `nil`:
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
decoder.decode(relation_message)
|
|
98
|
+
# => nil
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
An insert message returns a decoded event:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
event = decoder.decode(insert_message)
|
|
105
|
+
|
|
106
|
+
event.transaction_id
|
|
107
|
+
# => 789
|
|
108
|
+
|
|
109
|
+
event.schema
|
|
110
|
+
# => "public"
|
|
111
|
+
|
|
112
|
+
event.table
|
|
113
|
+
# => "users"
|
|
114
|
+
|
|
115
|
+
event.values
|
|
116
|
+
# => { "id" => 7, "name" => "Alice", "active" => true }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Transaction Context
|
|
122
|
+
|
|
123
|
+
PostgreSQL `pgoutput` carries the transaction ID in the `Begin` (`B`) message, not on every row-change message.
|
|
124
|
+
|
|
125
|
+
The decoder remembers the active transaction and attaches it to decoded DML events:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
decoder.decode(begin_message)
|
|
129
|
+
decoder.decode(relation_message)
|
|
130
|
+
insert = decoder.decode(insert_message)
|
|
131
|
+
|
|
132
|
+
insert.transaction_id
|
|
133
|
+
# => 789
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The transaction ID is useful for grouping changes, debugging, and CDC processing. It should not be treated as a globally permanent identifier because PostgreSQL transaction IDs can wrap around.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Supported Events
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
Pgoutput::Decoder::Events::Begin
|
|
144
|
+
Pgoutput::Decoder::Events::Commit
|
|
145
|
+
Pgoutput::Decoder::Events::Insert
|
|
146
|
+
Pgoutput::Decoder::Events::Update
|
|
147
|
+
Pgoutput::Decoder::Events::Delete
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Default Type Support
|
|
153
|
+
|
|
154
|
+
The default registry supports common scalar PostgreSQL OIDs:
|
|
155
|
+
|
|
156
|
+
| OID | Type |
|
|
157
|
+
| ---- | ---------------- |
|
|
158
|
+
| 16 | boolean |
|
|
159
|
+
| 20 | bigint |
|
|
160
|
+
| 21 | smallint |
|
|
161
|
+
| 23 | integer |
|
|
162
|
+
| 25 | text |
|
|
163
|
+
| 114 | json |
|
|
164
|
+
| 700 | real |
|
|
165
|
+
| 701 | double precision |
|
|
166
|
+
| 1043 | varchar |
|
|
167
|
+
| 1082 | date |
|
|
168
|
+
| 1114 | timestamp |
|
|
169
|
+
| 1184 | timestamptz |
|
|
170
|
+
| 1700 | numeric |
|
|
171
|
+
| 2950 | uuid |
|
|
172
|
+
| 3802 | jsonb |
|
|
173
|
+
|
|
174
|
+
Unsupported OIDs are returned as frozen raw strings.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Binary Values
|
|
179
|
+
|
|
180
|
+
Binary decoding is intentionally conservative.
|
|
181
|
+
|
|
182
|
+
The decoder handles safe fixed-width binary scalar types such as:
|
|
183
|
+
|
|
184
|
+
- boolean
|
|
185
|
+
- int2
|
|
186
|
+
- int4
|
|
187
|
+
- int8
|
|
188
|
+
- float4
|
|
189
|
+
- float8
|
|
190
|
+
|
|
191
|
+
Unsupported binary values are preserved as frozen raw bytes.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Custom OID Decoders
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
registry =
|
|
199
|
+
Pgoutput::Decoder::TypeRegistry.default.with_decoder(999_999) do |raw, format|
|
|
200
|
+
format == :text ? "custom:#{raw}" : raw
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
decoder = Pgoutput::Decoder.new(type_registry: registry)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Update Events
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
update = decoder.decode(update_message)
|
|
212
|
+
|
|
213
|
+
update.old_key
|
|
214
|
+
# => { "id" => 7 } or nil
|
|
215
|
+
|
|
216
|
+
update.old_values
|
|
217
|
+
# => { ... } or nil
|
|
218
|
+
|
|
219
|
+
update.new_values
|
|
220
|
+
# => { "id" => 7, "name" => "Bob" }
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Delete Events
|
|
226
|
+
|
|
227
|
+
```ruby
|
|
228
|
+
delete = decoder.decode(delete_message)
|
|
229
|
+
|
|
230
|
+
delete.old_key
|
|
231
|
+
# => { "id" => 7 } or nil
|
|
232
|
+
|
|
233
|
+
delete.old_values
|
|
234
|
+
# => { ... } or nil
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Ractor Safety
|
|
240
|
+
|
|
241
|
+
Decoded events are deeply shareable:
|
|
242
|
+
|
|
243
|
+
```ruby
|
|
244
|
+
event = decoder.decode(update_message)
|
|
245
|
+
|
|
246
|
+
Ractor.shareable?(event)
|
|
247
|
+
# => true
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The decoder instance itself is stateful and should not be shared across Ractors.
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Testing
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
bundle exec rake test
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
With coverage:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
COVERAGE=true bundle exec rake test
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Type Checking
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
bundle exec steep check
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT.
|
metadata
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pgoutput-decoder
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ken C. Demanawa
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: pgoutput-parser
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: pry
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.16.0
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.16.0
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: minitest
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '5.27'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '5.27'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rake
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '13.4'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '13.4'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rubocop
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.87'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.87'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: simplecov
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 0.22.0
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 0.22.0
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: steep
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '1.10'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1.10'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: yard
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: 0.9.44
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: 0.9.44
|
|
124
|
+
description: Decodes pgoutput-parser protocol messages into immutable Ruby row-change
|
|
125
|
+
events.
|
|
126
|
+
email:
|
|
127
|
+
- kenneth.c.demanawa@gmail.com
|
|
128
|
+
executables: []
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- CHANGELOG.md
|
|
133
|
+
- LICENSE.txt
|
|
134
|
+
- README.md
|
|
135
|
+
- lib/pgoutput/decoder.rb
|
|
136
|
+
- lib/pgoutput/decoder/version.rb
|
|
137
|
+
- sig/pgoutput/decoder.rbs
|
|
138
|
+
homepage: https://github.com/kanutocd/pgoutput-decoder
|
|
139
|
+
licenses:
|
|
140
|
+
- MIT
|
|
141
|
+
metadata:
|
|
142
|
+
homepage_uri: https://github.com/kanutocd/pgoutput-decoder
|
|
143
|
+
source_code_uri: https://github.com/kanutocd/pgoutput-decoder
|
|
144
|
+
changelog_uri: https://github.com/kanutocd/pgoutput-decoder/blob/main/CHANGELOG.md
|
|
145
|
+
rubygems_mfa_required: 'true'
|
|
146
|
+
rdoc_options: []
|
|
147
|
+
require_paths:
|
|
148
|
+
- lib
|
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ">="
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '3.4'
|
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0'
|
|
159
|
+
requirements: []
|
|
160
|
+
rubygems_version: 3.6.9
|
|
161
|
+
specification_version: 4
|
|
162
|
+
summary: PostgreSQL pgoutput logical replication value decoder.
|
|
163
|
+
test_files: []
|