diff --git a/examples/databases/src/sqlx.rs b/examples/databases/src/sqlx.rs index 0eb6a30f..c52cc2e7 100644 --- a/examples/databases/src/sqlx.rs +++ b/examples/databases/src/sqlx.rs @@ -24,12 +24,16 @@ struct Post { #[post("/", data = "")] async fn create(mut db: Connection, mut post: Json) -> Result>> { - let query = sqlx::query! { - "INSERT INTO posts (title, text) VALUES (?, ?) RETURNING id", - post.title, post.text - }; + // NOTE: sqlx#2543, sqlx#1648 mean we can't use the pithier `fetch_one()`. + let results = sqlx::query!( + "INSERT INTO posts (title, text) VALUES (?, ?) RETURNING id", + post.title, post.text + ) + .fetch(&mut **db) + .try_collect::>() + .await?; - post.id = Some(query.fetch_one(&mut **db).await?.id); + post.id = Some(results.first().expect("returning results").id); Ok(Created::new("/").body(post)) }