aboutsummaryrefslogtreecommitdiffstats
path: root/src/models/post.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/post.rs')
-rw-r--r--src/models/post.rs20
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));