-
-
Notifications
You must be signed in to change notification settings - Fork 477
ToSql for NewType structs? #311
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
Comments
rust-postgres-derive treats newtype structs as mapping to postgres domain types. If you want to transparently map through you'll need to implement the traits manually. |
Ok, gotcha. |
There is a gotcha with the So using the example in the documentation defining a let select_stmt = client
.prepare("SELECT * FROM users.test WHERE name = $1 AND session_id = $2")
.await
.unwrap();
let rows = client
.query(
&select_stmt,
&[&"blankhart", &SessionId([0; 16].to_vec())],
)
.await
.unwrap(); you would fail because Postgres expects the underlying If you define a newtype mapping to a custom domain you may still need to expose the underlying representation of the Rust type to interact with Postgres in this way. It seems to me that the ability to derive a transparent |
That is already handled in the generated code: https://github.com/sfackler/rust-postgres/blob/master/postgres-derive/src/fromsql.rs#L98-L110 |
Grateful if you could elaborate - my efforts have so far all generated errors when attempting conversions of this kind using the |
Oh - we need to add that extra logic to the ToSql implementation to then it seems. I'll make a fix tonight. |
Did that fix ever get in? I'm seeing an issue that seems the same as described by @blankhart in some of my code |
How would one work with new-type structs and
ToSql
?See the following example where I'm trying to use
pub struct Id(i32)
:The text was updated successfully, but these errors were encountered: