21 lines
546 B
Rust
21 lines
546 B
Rust
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<usize> {
|
|
diesel::insert_into(table_posts).values(self).execute(conn)
|
|
}
|
|
}
|