Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Record en-/decoder #258

Closed
ged opened this issue Mar 13, 2017 · 5 comments
Closed

Add Record en-/decoder #258

ged opened this issue Mar 13, 2017 · 5 comments

Comments

@ged
Copy link
Owner

ged commented Mar 13, 2017

Original report by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


Original post: https://groups.google.com/forum/#!topic/ruby-pg/ikdlp67c5RA

The current implementation of decoders and encoders doesn't support embedded Records of composite type?

What I'd like to do is decode the following example:

CREATE TYPE example AS (a string, b integer, c boolean);
CREATE TABLE test (id integer, sample example);
INSERT INTO test VALUES (1, '("Some text",123,false)');
SELECT * FROM test;

The query returns the following values, before decoder:

result['id'] === 1
result['sample'] === '("Some text",123,false)'

What I'd like to do is something like the "PG::TextDecoder::Array#decode" method, but with a mix of decoder functions, returning:

result['sample'] === ['Some text', 123, false]
@ged
Copy link
Owner Author

ged commented Mar 13, 2017

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


I started the implementation of a record en-/ decoder, but it's around 30% yet.

@ged
Copy link
Owner Author

ged commented Jun 11, 2018

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


The postgres implementation is in rowtypes.c. We need a new Coder type next to PG::SimpleCoder, PG::CopyCoder and PG::CompositeCoder. I would call it PG::RowCoder. I haven't got it further so far - still around 30%.

@ged
Copy link
Owner Author

ged commented Mar 27, 2019

Original comment by Carlos Ferreira da Silva (Bitbucket: crash-tech, GitHub: crash-tech).


Is this still a feature to come? I built this gem PostgreSQL that relies deeply on these advanced features from PostgreSQL, and requires correct decoding and encoding of the data. I've created this override Torque::PostgreSQL::Coder which is basically an extension of the current available Decoder/Encoder. Let me know if I can help with this, the change seems to be pretty simple and maybe I can open a PR for that.

@ged
Copy link
Owner Author

ged commented Apr 6, 2019

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


I implemented the required encoder and decoder in C: #36

@ged
Copy link
Owner Author

ged commented Oct 4, 2019

Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).


Add PG::RowCoder for en/decoding of Composite Types

This implements proper encoder and decoder for Composite Types
as described in https://www.postgresql.org/docs/11/rowtypes.html
and as requested in https://bitbucket.org/ged/ruby-pg/issues/258

This adds the following classes:

  • PG::RowCoder < PG::Coder
  • PG::RowEncoder < PG::RowCoder
  • PG::RowDecoder < PG::RowCoder
  • PG::TextEncoder::Row < PG::RowEncoder
  • PG::TextDecoder::Row < PG::RowDecoder

Fixes #258

@ged ged closed this as completed Oct 4, 2019
@ged ged added this to the Pending milestone Oct 8, 2019
larskanis added a commit that referenced this issue Oct 9, 2019
This implements proper encoder and decoder for Composite Types
as described in https://www.postgresql.org/docs/11/rowtypes.html
and as requested in https://bitbucket.org/ged/ruby-pg/issues/258

This adds the following classes:
* PG::RowCoder < PG::Coder
* PG::RowEncoder < PG::RowCoder
* PG::RowDecoder < PG::RowCoder
* PG::TextEncoder::Row < PG::RowEncoder
* PG::TextDecoder::Row < PG::RowDecoder

Fixes #258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant