When using sqlx, I have a match block as follows:
let messages_option = match time_range {
TimeRange {before: Some(before), after: Some(after)} => {
sqlx::query!("SELECT * FROM messages WHERE timestamp BETWEEN ? AND ?", after, before)
.fetch_all(&mut conn)
.await
},
TimeRange {before: None, after: Some(after)} => {
sqlx::query!("SELECT * FROM messages WHERE timestamp > ?", after)
.fetch_all(&mut conn)
.await
},
TimeRange {before: Some(before), after: None} => {
sqlx::query!("SELECT * FROM messages WHERE timestamp < ?", before)
.fetch_all(&mut conn)
.await
},
TimeRange {before: None, after: None} => {
sqlx::query!("SELECT * FROM messages")
.fetch_all(&mut conn)
.await
}
};
When building, it gives the following error:
135 | let messages_option = match time_range {
| ---------------- `match` arms have incompatible types
136 | TimeRange {before: Some(before), after: Some(after)} => {
137 | / sqlx::query!("SELECT * FROM messages WHERE timestamp BETWEEN ? AND ?", after, before)
138 | | .fetch_all(&mut conn)
139 | | .await
| |______________________- this is found to be of type `Result<Vec<query_db::{closure#0}::Record>, sqlx::Error>`
...
142 | / sqlx::query!("SELECT * FROM messages WHERE timestamp > ?", after)
143 | | .fetch_all(&mut conn)
144 | | .await
| |______________________^ expected `query_db::{closure#0}::Record`, found a different `query_db::{closure#0}::Record`
|
= note: expected enum `Result<Vec<query_db::{closure#0}::Record>, _>` (`query_db::{closure#0}::Record`)
found enum `Result<Vec<query_db::{closure#0}::Record>, _>` (`query_db::{closure#0}::Record`)
It says "expected query_db::{closure#0}::Record, found a different query_db::{closure#0}::Record", but the types look exactly the same, then why the incompatibility?
Please help. Thanks!