Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created November 7, 2021 17:08
Show Gist options
  • Select an option

  • Save jayhuang75/62bb3912a9095c65f2e2e6e40edef6b6 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/62bb3912a9095c65f2e2e6e40edef6b6 to your computer and use it in GitHub Desktop.
go train delay rust api sqlx get all
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