Created
November 7, 2021 17:08
-
-
Save jayhuang75/62bb3912a9095c65f2e2e6e40edef6b6 to your computer and use it in GitHub Desktop.
go train delay rust api sqlx get all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let q = format!( | |
| "select | |
| date, | |
| departure, | |
| depart_scheduled, | |
| destination, | |
| arrival_scheduled, | |
| delay, | |
| created_at, | |
| count(*) OVER() AS total_count | |
| from delays | |
| ORDER BY created_at DESC | |
| LIMIT {} | |
| OFFSET {}", | |
| &limit, &offset | |
| ); | |
| let delays = sqlx::query_as::<_, Delay>(&q).fetch_all(&state.db).await?; | |
| if delays.is_empty() { | |
| return Ok(HttpResponse::InternalServerError().json(AppError{ | |
| message: Some("no record found".to_string()), | |
| cause: Some("out of record range".to_string()), | |
| error_type: AppErrorType::DbError, | |
| })); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment