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;