delete posts
cargo devel CI / cargo CI (push) Successful in 3m17s
Details
cargo devel CI / cargo CI (push) Successful in 3m17s
Details
This commit is contained in:
parent
0bf4b474df
commit
2edb979aef
|
@ -56,6 +56,13 @@ fn repl(conn: &mut SqliteConnection) -> anyhow::Result<()> {
|
||||||
Some(i) => i,
|
Some(i) => i,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
if let Err(e) = Post::delete(conn, id){
|
||||||
|
if let Some(e) = e.downcast_ref::<diesel::result::Error>() {
|
||||||
|
if matches!(e, diesel::result::Error::NotFound) {
|
||||||
|
warn!("No post with id {id} exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
} else if buf.starts_with("LIST") {
|
} else if buf.starts_with("LIST") {
|
||||||
let posts = lib::load_all_posts(conn)?;
|
let posts = lib::load_all_posts(conn)?;
|
||||||
trace!("loaded posts for display: {posts:#?}");
|
trace!("loaded posts for display: {posts:#?}");
|
||||||
|
|
|
@ -32,6 +32,15 @@ impl Post {
|
||||||
info!("updated post {}", post.id);
|
info!("updated post {}", post.id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
pub fn delete(conn: &mut SqliteConnection, id: i32) -> anyhow::Result<()> {
|
||||||
|
use crate::schema::posts::dsl::{posts, published};
|
||||||
|
|
||||||
|
let post = diesel::delete(posts.find(id))
|
||||||
|
.returning(Post::as_returning())
|
||||||
|
.get_result(conn)?;
|
||||||
|
info!("deleted post {}", post.id);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, Debug)]
|
#[derive(Insertable, Debug)]
|
||||||
|
|
Loading…
Reference in New Issue