Skip to main content

filter_keys

Function filter_keys 

Source
pub fn filter_keys<M>(records: &[M]) -> Expr<bool>
where M: Model + IntoExpr<M>,
Expand description

The predicate selecting each of records by its primary key, so that an action writes the same change to all of them in one statement rather than one per record:

async fn run(
    _cx: &Cx,
    posts: &[Post],
    _: (),
    ex: &mut dyn Executor,
) -> Result<tablo_core::Outcome, tablo_core::WriteError<()>> {
    Post::filter(filter_keys(posts))
        .update()
        .status("published".to_string())
        .exec(ex)
        .await?;
    Ok(tablo_core::Outcome::done())
}

A single key selects through one IN list, a composite key through one equality per record, and no record selects no row. The predicate scopes nothing itself: it selects exactly the records given, which for an Action the pipeline loaded through the tenant-scoped query and checked against the policy, no more than Limits::bulk_records of them.

The statement binds a value per key, which databases bound: SQLite takes 32,766 values, and nests the equalities of composite keys no more than 1,000 deep. A set the caller loaded itself, as a HeaderAction does, has no such bound: write it in chunks, a few hundred records each.