Replies: 1 comment
-
You can override the type inference in the macros. This example shows how to force a custom type that is optional. let mut conn = PgConnection::connect("...").await?;
struct Tweet {
id: Option<ID>
}
let user: Tweet = sqlx::query_as!(Tweet, r#"select id as "id?: ID" from tweet"#)
.fetch_one(&mut conn)
.await?; For other ways to override types in the macro's, take a look at this table. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For example, I implemented an ID which is essentially a wrapper around
i64
, and also implemented theFrom<i64>
trait for it:When using
query_as!
, it can be directly converted in non-Option
cases. The macro generated code looks like this:But for
Option
cases,Option<i64>
doesn't automatically convert toOption<ID>
:Why isn't the macro generating code in this form instead ?
Did I overlook something ?
Beta Was this translation helpful? Give feedback.
All reactions