use crate::schema::posts::{self, dsl::posts as table_posts}; use chrono::NaiveDateTime; use diesel::{QueryResult, RunQueryDsl}; #[derive(Insertable)] #[table_name = "posts"] pub struct NewPost<'a> { pub parent: Option<&'a i32>, pub timestamp: NaiveDateTime, pub author: &'a str, pub email: &'a str, pub title: &'a str, pub content: &'a str, } impl NewPost<'_> { pub fn insert(&self, conn: &diesel::SqliteConnection) -> QueryResult { diesel::insert_into(table_posts).values(self).execute(conn) } }