From 653267344fb1dce5ba2ecd3664bfef3921f8e86d Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Thu, 8 Jul 2021 17:13:35 +0200 Subject: [PATCH] Update --- src/main.rs | 6 +++--- src/models/mod.rs | 1 + src/{ => models}/task.rs | 15 ++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 src/models/mod.rs rename src/{ => models}/task.rs (68%) diff --git a/src/main.rs b/src/main.rs index bcd8c1e..49a671a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_migrations; +mod models; + use rocket::*; use rocket::fairing::AdHoc; use rocket_sync_db_pools::{database}; -mod task; - #[database("sqlite_logs")] pub struct DbConn(diesel::SqliteConnection); @@ -17,7 +17,7 @@ fn index() -> &'static str { #[get("/log/")] async fn get_log(conn: DbConn, id: i32) -> String { - let result = task::Task::all(&conn).await; + let result = models::task::Task::all(&conn).await; format!("test {}, {:?}", id, result) } diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..2f2b628 --- /dev/null +++ b/src/models/mod.rs @@ -0,0 +1 @@ +pub mod task; \ No newline at end of file diff --git a/src/task.rs b/src/models/task.rs similarity index 68% rename from src/task.rs rename to src/models/task.rs index 7731f92..d7dcd99 100644 --- a/src/task.rs +++ b/src/models/task.rs @@ -1,18 +1,15 @@ use rocket::serde::Serialize; use diesel::{self, result::QueryResult, Queryable, Insertable, prelude::*}; -mod schema { - table! { - tasks { - id -> Nullable, - description -> Text, - completed -> Bool, - } +table! { + tasks { + id -> Nullable, + description -> Text, + completed -> Bool, } } -use schema::tasks; -use schema::tasks::dsl::{tasks as all_tasks}; +use tasks::dsl::{tasks as all_tasks}; use crate::DbConn;