1
0
Fork 0

update rocket and add diesel

This commit is contained in:
Florian RICHER 2021-07-08 09:00:00 +02:00
parent e7ce218de5
commit c54cdc98ba
11 changed files with 1414 additions and 308 deletions

34
src/task.rs Normal file
View file

@ -0,0 +1,34 @@
use rocket::serde::Serialize;
use diesel::{self, result::QueryResult, Queryable, Insertable, prelude::*};
mod schema {
table! {
tasks {
id -> Nullable<Integer>,
description -> Text,
completed -> Bool,
}
}
}
use schema::tasks;
use schema::tasks::dsl::{tasks as all_tasks, completed as task_completed};
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
}
}