blob: 8bf933ebccb6e7d2b2268bb5f95dffffe91da6ef (
plain) (
tree)
|
|
use super::schema::posts;
use diesel::prelude::*;
#[derive(Serialize, Queryable)]
pub struct Post {
pub id: i32,
pub title: String,
pub body: String,
pub published: bool,
}
pub fn get_posts(conn: ::DbConn) -> Vec<Post> {
use super::schema::posts::dsl::*;
posts.filter(published.eq(false))
.limit(5)
.load::<Post>(&*conn)
.expect("Error loading posts")
}
#[derive(Default, FromForm, Insertable)]
#[table_name="posts"]
pub struct NewPost {
pub title: String,
pub body: String,
pub published: bool,
}
|