From ad0e585abed7a189b6117e9187c9afff809d1414 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 8 Apr 2019 15:55:14 +0200 Subject: Move functions to query/modify db to connection object. Makes tha API a bit nicer by asking the database rather than passing the database on to each model. Reserve models for method/functions that work on the model structs themselves. --- src/models/film.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/models/film.rs') diff --git a/src/models/film.rs b/src/models/film.rs index 8207e5d..8f17d42 100644 --- a/src/models/film.rs +++ b/src/models/film.rs @@ -16,11 +16,7 @@ along with this program. If not, see . */ -use crate::{ - db::Connection, - schema::films, -}; -use diesel::prelude::*; +use crate::schema::films; use serde_derive::{Deserialize, Serialize}; #[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)] @@ -36,15 +32,3 @@ pub struct NewFilm<'a> { pub title: &'a str, pub url: Option<&'a str>, } - -pub fn get_all(db: &Connection) -> QueryResult> { - use crate::schema::films::dsl::*; - films.load::(&**db) -} - -pub fn by_title(ftitle: &str, db: &Connection) -> QueryResult { - use crate::schema::films::dsl::*; - films - .filter(title.eq(&ftitle)) - .get_result::(&**db) -} -- cgit v1.2.3