Replies: 1 comment 2 replies
-
I was jut looking for an answer myself. This worked for me: let output = query_as!(
Self,
r###"SELECT id as "id: u32" FROM my_table LIMIT 1"###
)
.fetch_one(pool)
.await?; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm getting an integer from somewhere else, and I know it's unsigned. So now I'd like a convenient way to have my type using an unsigned integer, whilst still being able to store it with sqlx. I imagine there are many scenarios like this, where you need a single field or a couple to convert to DB-compatible equivalents. I've found many ways of handling this but non all that convenient.
Naturally, Postgres can only store what it can store, in my case I know the unsigned integer fits inside a signed integer. The inserting is no big deal, you need to bind each field anyway and can easily cast or
Into
there. Getting them out seems less convenient because it can all be done automatically if your Rust types match the DB types, or you have to do them all by hand.Methods I've discovered so far:
.map
by hand usingas u32
to cast.query_as!
with aMyTypeRow
then write aFrom<MyTypeRow> for MyType
.Better ways to do this?
Beta Was this translation helpful? Give feedback.
All reactions