-
-
Notifications
You must be signed in to change notification settings - Fork 487
Add a Row-like interface to any PostgreSQL composite type #565
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
base: master
Are you sure you want to change the base?
Conversation
This adds a new type CompositeType that implements FromSql and has the same interface as Row.
@@ -531,11 +532,12 @@ pub struct DataRowBody { | |||
|
|||
impl DataRowBody { | |||
#[inline] | |||
pub fn ranges(&self) -> DataRowRanges<'_> { | |||
pub fn ranges(&self) -> DataRowRanges<'_, DataRow> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module is specifically for parsing the backend protocol messages. I'd rather have composite support added in the types module.
tokio-postgres/src/row.rs
Outdated
} | ||
|
||
impl<'a> CompositeType<'a> { | ||
pub(crate) fn new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this can just be inlined in to the FromSql implementation.
Move code from CompositeType::new to FromSql::from_sql. Move support for composite types from message/backend.rs to types/mod.rs.
I moved the code from |
Is there something blocking this? It is something I'm quite interested in myself. |
I'm also still interested in this. I can update the PR if necessary. |
I've rebased this PR against current |
If you need this before its merged, you can also just copy the structs from this PR into your codebase to use it without needing to fork this library. An example of this can be found here: https://github.com/spiceai/spiceai/blob/trunk/crates/arrow_sql_gen/src/postgres/composite.rs |
It can be useful to be able to get fields of a composite type without the need to derive
FromSql
for a structure (#366).This PR adds a new type
CompositeType
that implementsFromSql
and has the same methods asRow
.Example:
The binary format of a composite type is different from the format of a
DataRow
(there is an OID before each length/value pair), so I added a type parameter toDataRowRanges
to makeFallibleIterator
for ranges usable for both cases:https://github.com/alexwl/rust-postgres/blob/aa4b5547e3bf13e112ae90dd919b0ac70d67ebaa/postgres-protocol/src/message/backend.rs#L550-L574