Order posts by id
This commit is contained in:
parent
6b17cc50bc
commit
3f41f92690
@ -6,12 +6,12 @@ use rocket::form::{Context, Form};
|
||||
use rocket::fs::{relative, FileServer};
|
||||
use rocket::request::FlashMessage;
|
||||
use rocket::response::{Flash, Redirect};
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::{Build, Request, Rocket};
|
||||
use rocket_db_pools::{sqlx, Connection, Database};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
|
||||
use sea_orm::entity::*;
|
||||
use sea_orm::QueryOrder;
|
||||
use sea_orm::RocketDbPool;
|
||||
|
||||
mod setup;
|
||||
@ -72,6 +72,7 @@ async fn update(conn: Connection<Db>, id: i64, post_form: Form<post::Model>) ->
|
||||
#[get("/")]
|
||||
async fn list(conn: Connection<Db>, flash: Option<FlashMessage<'_>>) -> Template {
|
||||
let posts = Post::find()
|
||||
.order_by_asc(post::Column::Id)
|
||||
.all(&conn)
|
||||
.await
|
||||
.expect("could not retrieve posts")
|
||||
|
@ -58,9 +58,6 @@ button.small {
|
||||
margin: 0 2.5px;
|
||||
}
|
||||
|
||||
.post {
|
||||
}
|
||||
|
||||
.post:hover {
|
||||
background-color: #bce2ee;
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ macro_rules! try_getable_all {
|
||||
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
#[allow(unused_variables)]
|
||||
QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| {
|
||||
debug_print!("{:#?}", e.to_string());
|
||||
TryGetError::Null
|
||||
@ -138,6 +139,7 @@ macro_rules! try_getable_unsigned {
|
||||
.and_then(|opt| opt.ok_or(TryGetError::Null))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
#[allow(unused_variables)]
|
||||
QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| {
|
||||
debug_print!("{:#?}", e.to_string());
|
||||
TryGetError::Null
|
||||
@ -170,6 +172,7 @@ macro_rules! try_getable_mysql {
|
||||
panic!("{} unsupported by sqlx-sqlite", stringify!($type))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
#[allow(unused_variables)]
|
||||
QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| {
|
||||
debug_print!("{:#?}", e.to_string());
|
||||
TryGetError::Null
|
||||
@ -202,6 +205,7 @@ macro_rules! try_getable_postgres {
|
||||
panic!("{} unsupported by sqlx-sqlite", stringify!($type))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
#[allow(unused_variables)]
|
||||
QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| {
|
||||
debug_print!("{:#?}", e.to_string());
|
||||
TryGetError::Null
|
||||
@ -264,12 +268,16 @@ impl TryGetable for Decimal {
|
||||
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))?;
|
||||
use rust_decimal::prelude::FromPrimitive;
|
||||
match val {
|
||||
Some(v) => Decimal::from_f64(v)
|
||||
.ok_or_else(|| TryGetError::DbErr(DbErr::Query("Failed to convert f64 into Decimal".to_owned()))),
|
||||
None => Err(TryGetError::Null)
|
||||
Some(v) => Decimal::from_f64(v).ok_or_else(|| {
|
||||
TryGetError::DbErr(DbErr::Query(
|
||||
"Failed to convert f64 into Decimal".to_owned(),
|
||||
))
|
||||
}),
|
||||
None => Err(TryGetError::Null),
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
#[allow(unused_variables)]
|
||||
QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| {
|
||||
debug_print!("{:#?}", e.to_string());
|
||||
TryGetError::Null
|
||||
|
Loading…
x
Reference in New Issue
Block a user