Skip to main content

delete

Function delete 

Source
pub fn delete(
    ctx: &Ctx,
    key: &str,
) -> impl Future<Output = Result<()>> + Send + use<>
Expand description

Deletes the object at key.

Deleting a missing key is not an error, so a retried cleanup is safe. Delete the object only once no row points to it any more (after the database write succeeded). R2 deletes are free.

§Errors

Error::Internal (500) when the STORAGE binding is missing (the message shows the STORAGE entry to add to cloudflare.config.ts) or R2 fails.

§Examples

use axum::{extract::{Path, State}, http::StatusCode};
use ocre::{Ctx, Result, params, storage};

// DELETE /exports/{key}: forget a generated export.
async fn destroy(State(ctx): State<Ctx>, Path(key): Path<String>) -> Result<StatusCode> {
    ctx.db()?.execute("DELETE FROM exports WHERE file_key = ?1", params![key.as_str()]).await?;
    storage::delete(&ctx, &key).await?;
    Ok(StatusCode::NO_CONTENT)
}