File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,16 @@ struct Post {
2424
2525#[ post( "/" , data = "<post>" ) ]
2626async fn create ( mut db : Connection < Db > , mut post : Json < Post > ) -> Result < Created < Json < Post > > > {
27- let query = sqlx:: query! {
28- "INSERT INTO posts (title, text) VALUES (?, ?) RETURNING id" ,
29- post. title, post. text
30- } ;
27+ // NOTE: sqlx#2543, sqlx#1648 mean we can't use the pithier `fetch_one()`.
28+ let results = sqlx:: query!(
29+ "INSERT INTO posts (title, text) VALUES (?, ?) RETURNING id" ,
30+ post. title, post. text
31+ )
32+ . fetch ( & mut * * db)
33+ . try_collect :: < Vec < _ > > ( )
34+ . await ?;
3135
32- post. id = Some ( query . fetch_one ( & mut * * db ) . await ? . id ) ;
36+ post. id = Some ( results . first ( ) . expect ( "returning results" ) . id ) ;
3337 Ok ( Created :: new ( "/" ) . body ( post) )
3438}
3539
You can’t perform that action at this time.
0 commit comments