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

View file

@ -1,12 +1,12 @@
#[macro_use] extern crate diesel; #[macro_use] extern crate diesel;
#[macro_use] extern crate diesel_migrations; #[macro_use] extern crate diesel_migrations;
mod models;
use rocket::*; use rocket::*;
use rocket::fairing::AdHoc; use rocket::fairing::AdHoc;
use rocket_sync_db_pools::{database}; use rocket_sync_db_pools::{database};
mod task;
#[database("sqlite_logs")] #[database("sqlite_logs")]
pub struct DbConn(diesel::SqliteConnection); pub struct DbConn(diesel::SqliteConnection);
@ -17,7 +17,7 @@ fn index() -> &'static str {
#[get("/log/<id>")] #[get("/log/<id>")]
async fn get_log(conn: DbConn, id: i32) -> String { 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) format!("test {}, {:?}", id, result)
} }

1
src/models/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod task;

View file

@ -1,7 +1,6 @@
use rocket::serde::Serialize; use rocket::serde::Serialize;
use diesel::{self, result::QueryResult, Queryable, Insertable, prelude::*}; use diesel::{self, result::QueryResult, Queryable, Insertable, prelude::*};
mod schema {
table! { table! {
tasks { tasks {
id -> Nullable<Integer>, id -> Nullable<Integer>,
@ -9,10 +8,8 @@ mod schema {
completed -> Bool, completed -> Bool,
} }
} }
}
use schema::tasks; use tasks::dsl::{tasks as all_tasks};
use schema::tasks::dsl::{tasks as all_tasks};
use crate::DbConn; use crate::DbConn;