diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 14:29:50 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 19:40:57 +0200 |
commit | b9bce0c426ab258f2c5891ac7eecd944f749e27c (patch) | |
tree | 3981bc54a4b0602d918ea378bc0847ea3a988633 /src/models/post.rs | |
parent | d9a217e3b73a702875c2907d7d1811c3dd82d8e9 (diff) | |
download | rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.tar.gz rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.tar.bz2 rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.zip |
Run rustfmt on project.
Diffstat (limited to 'src/models/post.rs')
-rw-r--r-- | src/models/post.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/models/post.rs b/src/models/post.rs index 17ac74a..be44dda 100644 --- a/src/models/post.rs +++ b/src/models/post.rs @@ -1,6 +1,6 @@ -use schema::posts; -use diesel::prelude::*; use diesel; +use diesel::prelude::*; +use schema::posts; use utils; #[derive(AsChangeset, FromForm, Identifiable, Serialize, Queryable)] @@ -12,7 +12,7 @@ pub struct Post { } #[derive(Default, FromForm, Insertable)] -#[table_name="posts"] +#[table_name = "posts"] pub struct NewPost { pub title: String, pub body: String, @@ -21,16 +21,18 @@ pub struct NewPost { impl Post { pub fn get_all(conn: utils::DbConn) -> Vec<Post> { - use ::schema::posts::dsl::*; - posts.filter(published.eq(false)) + use schema::posts::dsl::*; + posts + .filter(published.eq(false)) .limit(5) .load::<Post>(&*conn) .expect("Error loading posts") } fn get_internal(post_id: i32, conn: &utils::DbConn) -> Post { - use ::schema::posts::dsl::*; - posts.find(post_id) + use schema::posts::dsl::*; + posts + .find(post_id) .get_result(&**conn) .expect(&format!("Unable to find post with id={}", post_id)) } @@ -40,7 +42,7 @@ impl Post { } pub fn create(new_post: &NewPost, conn: utils::DbConn) { - use ::schema::posts::dsl::*; + use schema::posts::dsl::*; diesel::insert_into(posts) .values(new_post) .execute(&*conn) @@ -56,7 +58,7 @@ impl Post { } pub fn delete(post_id: i32, conn: utils::DbConn) { - use ::schema::posts::dsl::*; + use schema::posts::dsl::*; diesel::delete(posts.filter(id.eq(post_id))) .execute(&*conn) .expect(&format!("Could not delete post with id {}", post_id)); |