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
larskanis opened this issue Mar 13, 2017 · 5 comments
Closed

Add Record en-/decoder #258

larskanis opened this issue Mar 13, 2017 · 5 comments
Labels
Milestone

Comments

@larskanis
Copy link
Owner

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]
@larskanis
Copy link
Owner Author

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


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

@larskanis
Copy link
Owner Author

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%.

@larskanis
Copy link
Owner Author

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.

@larskanis
Copy link
Owner Author

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


I implemented the required encoder and decoder in C: ged/ruby-pg#36

@larskanis
Copy link
Owner Author

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

@larskanis larskanis added this to the Pending milestone Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant