Skip to content

How to properly use UUID with sqlx? #1548

Answered by marknefedov
marknefedov asked this question in Q&A
Discussion options

You must be logged in to vote

@jplatte Answered in discord:
query_as is for getting a type that implements FromRow, not Type
What you need if you just want the single column of the output is query_scalar
You could also use a one-tuple, but that's kind of ugly which is why there is query_scalar

let (id,) = sqlx::query_as::<_, (Uuid,)>(
    "INSERT INTO users (name, password, email) VALUES ($1, $2, $3) RETURNING id",
)
.bind(...)
.fetch_one(&self.pool)
.await?;

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by marknefedov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants