Created
March 26, 2016 17:45
-
-
Save tgandrews/7c466d5e85bc3918c5d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use diesel::prelude::*; | |
use diesel::pg::PgConnection; | |
use models::Post; | |
use schema::posts::dsl::*; | |
use db::establish_connection; | |
pub struct PostStore { | |
connection: PgConnection | |
} | |
impl PostStore { | |
pub fn new() -> PostStore { | |
PostStore{connection: establish_connection()}; | |
} | |
pub fn get_all(&self) -> Option<Vec<Post>> { | |
let connection = establish_connection(); | |
let result = posts.load::<Post>(&self.connection); | |
match result { | |
Result::Ok(p) => Some(p), | |
Result::Err(err) => None | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment