1
0
Fork 0
This commit is contained in:
Florian RICHER 2021-07-08 17:13:35 +02:00
parent ee2bfbb769
commit 653267344f
3 changed files with 10 additions and 12 deletions

31
src/models/task.rs Normal file
View file

@ -0,0 +1,31 @@
use rocket::serde::Serialize;
use diesel::{self, result::QueryResult, Queryable, Insertable, prelude::*};
table! {
tasks {
id -> Nullable<Integer>,
description -> Text,
completed -> Bool,
}
}
use tasks::dsl::{tasks as all_tasks};
use crate::DbConn;
#[derive(Serialize, Queryable, Insertable, Debug, Clone)]
#[serde(crate = "rocket::serde")]
#[table_name="tasks"]
pub struct Task {
pub id: Option<i32>,
pub description: String,
pub completed: bool
}
impl Task {
pub async fn all(conn: &DbConn) -> QueryResult<Vec<Task>> {
conn.run(|c| {
all_tasks.order(tasks::id.desc()).load::<Task>(c)
}).await
}
}