Skip to content

Instantly share code, notes, and snippets.

@tgandrews
Created March 26, 2016 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgandrews/7c466d5e85bc3918c5d5 to your computer and use it in GitHub Desktop.
Save tgandrews/7c466d5e85bc3918c5d5 to your computer and use it in GitHub Desktop.
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