https://dev.classmethod.jp/articles/rust-loco/
この記事でのLocoで articles
での全削除がなかった。
SeaORMっていうO/Rマッパー使ってるっぽいので
https://www.sea-ql.org/SeaORM/docs/0.6.x/basic-crud/delete/
を調べた。
削除のルートを追加。
pub fn routes() -> Routes { Routes::new() .prefix("articles") .add("/", get(list)) .add("/", post(add)) .add("/:id", get(get_one)) .add("/:id", delete(remove)) .add("/:id", post(update)) .add("/:id/comments", get(comments)) // ここに追加 .add("/", delete(remove_all)) }
remove_all
のメソッドを追加
pub async fn remove_all(State(ctx): State<AppContext>) -> Result<()> { let delete_result = Entity::delete_many() .exec(&ctx.db) .await?; println!("Deleted {} rows", delete_result.rows_affected); format::empty() }
curl -X DELETE localhost:3000/articles