From 97a3704472739613b867b9c1b9f8819d80118b22 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 5 Apr 2019 19:06:43 -0400 Subject: [PATCH] Actually use Diesel schema macros --- migrations/2019-03-27-132202_first_tables/up.sql | 1 - src/handlers.rs | 5 +---- src/lib.rs | 7 ++++++- src/models.rs | 7 ++----- src/schema.rs | 2 -- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/migrations/2019-03-27-132202_first_tables/up.sql b/migrations/2019-03-27-132202_first_tables/up.sql index 551862e..9e07369 100644 --- a/migrations/2019-03-27-132202_first_tables/up.sql +++ b/migrations/2019-03-27-132202_first_tables/up.sql @@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS public.media_type ( CONSTRAINT media_type_pkey PRIMARY KEY (id) ); - CREATE TABLE IF NOT EXISTS public.media_format ( id serial NOT NULL, is_physical boolean NOT NULL DEFAULT false, diff --git a/src/handlers.rs b/src/handlers.rs index 756d516..663fb47 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,13 +1,10 @@ - use handlebars_iron::handlebars::to_json; use handlebars_iron::Template; use iron::prelude::{Request, Response}; use iron::{IronResult, Set, status}; use mount::Mount; -use serde::ser::Serialize as ToJson; use serde_json::value::{Map, Value}; use staticfile::Static; -use std::error::Error; use std::path::Path; pub fn render_page(name: &str, mut template_data: Map) -> Template { @@ -37,4 +34,4 @@ pub fn hello_world (_request: &mut Request) -> IronResult { .set_mut(status::Ok); Ok(response) -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 7fe987a..f5eed47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,11 @@ +#[macro_use] +extern crate diesel; + pub mod chain; pub mod db; pub mod handlers; pub mod models; -// pub mod schema; + +#[macro_use] +pub mod schema; diff --git a/src/models.rs b/src/models.rs index 7bf6b2e..826b53e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,9 +1,8 @@ use diesel::Queryable; -// use crate::schema::*; +use crate::schema::*; #[derive(Debug, Queryable)] -// #[table_name="media"] pub struct Media { pub id: u32, pub display_name: String, @@ -11,7 +10,6 @@ pub struct Media { } #[derive(Debug, Queryable)] -// #[table_name="media_type"] pub struct MediaType { pub id: u32, pub type_name: String, @@ -19,7 +17,6 @@ pub struct MediaType { } #[derive(Debug, Queryable)] -// #[table_name="media_format"] pub struct MediaFormat { pub id: u32, pub is_physical: bool, @@ -31,4 +28,4 @@ pub struct MediaFormat { pub struct MediaTypeFormatLink { pub media_type_id: i32, pub media_format_id: i32, -} \ No newline at end of file +} diff --git a/src/schema.rs b/src/schema.rs index c9e9ba1..6b5bf23 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,5 +1,3 @@ -use diesel::macros::*; - table! { /// Representation of the `media_format` table. ///