aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-01-11 22:41:09 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-01-11 22:41:09 +0100
commit22bac37fcaa1b1cdf8755754184ec8b3ace313b1 (patch)
tree41e6b4ec69b173313c257d9c74b8e62fce6028b1 /src/models
parent757770635c4c2537b03f9b1fb1576a8bf4609a72 (diff)
downloadrocket-blog-22bac37fcaa1b1cdf8755754184ec8b3ace313b1.tar.gz
rocket-blog-22bac37fcaa1b1cdf8755754184ec8b3ace313b1.tar.bz2
rocket-blog-22bac37fcaa1b1cdf8755754184ec8b3ace313b1.zip
Drop the lib.
The misc stuff from the lib root was moved to the utils module (terrible name, it's meant to be temporary.) The modules under the lib has been moved directly under the app.
Diffstat (limited to 'src/models')
-rw-r--r--src/models/post.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/models/post.rs b/src/models/post.rs
index b8453ce..922dbca 100644
--- a/src/models/post.rs
+++ b/src/models/post.rs
@@ -1,6 +1,7 @@
-use ::schema::posts;
+use schema::posts;
use diesel::prelude::*;
use diesel::{self, ExecuteDsl};
+use utils;
#[derive(AsChangeset, FromForm, Identifiable, Serialize, Queryable)]
pub struct Post {
@@ -19,7 +20,7 @@ pub struct NewPost {
}
impl Post {
- pub fn get_all(conn: ::DbConn) -> Vec<Post> {
+ pub fn get_all(conn: utils::DbConn) -> Vec<Post> {
use ::schema::posts::dsl::*;
posts.filter(published.eq(false))
.limit(5)
@@ -27,25 +28,25 @@ impl Post {
.expect("Error loading posts")
}
- fn get_internal(post_id: i32, conn: &::DbConn) -> Post {
+ fn get_internal(post_id: i32, conn: &utils::DbConn) -> Post {
use ::schema::posts::dsl::*;
posts.find(post_id)
.get_result(&**conn)
.expect(&format!("Unable to find post with id={}", post_id))
}
- pub fn get(post_id: i32, conn: ::DbConn) -> Post {
+ pub fn get(post_id: i32, conn: utils::DbConn) -> Post {
Post::get_internal(post_id, &conn)
}
- pub fn create(new_post: &NewPost, conn: ::DbConn) {
+ pub fn create(new_post: &NewPost, conn: utils::DbConn) {
diesel::insert(new_post)
.into(posts::table)
.execute(&*conn)
.expect("Error saving post.");
}
- pub fn update(updated_post: &Post, conn: ::DbConn) {
+ pub fn update(updated_post: &Post, conn: utils::DbConn) {
let p = Post::get_internal(updated_post.id, &conn);
diesel::update(&p)
.set(updated_post)