cratestack_sqlx/audit/outcome.rs
1//! [`RunInTxOutcome`] — what every write builder's `run_in_tx` returns
2//! (cratestack#534). It pairs the normal `.run(..)`-equivalent return
3//! value with the [`AuditEvent`]s the call already built and persisted
4//! to `cratestack_audit` inside the caller's transaction, so a caller
5//! who owns that transaction can fan them out to the installed
6//! `AuditSink` once *they* commit. See [`super::sink::dispatch_audit_sink`]'s
7//! doc comment for the full contract this exists to serve, and why
8//! `run_in_tx` cannot dispatch the events itself.
9
10use cratestack_core::AuditEvent;
11
12/// See the module doc comment.
13#[derive(Debug, Clone)]
14pub struct RunInTxOutcome<T> {
15 /// Exactly what the equivalent `.run(..)` call would have
16 /// returned.
17 pub value: T,
18 /// `AuditEvent`s already persisted to `cratestack_audit` by this
19 /// call, in mutation order. Empty when the model isn't
20 /// `@@audit`-enabled, or (for `.upsert(..).do_nothing()`) when the
21 /// conflict target already existed and nothing was written.
22 /// Single-row writes build at most one; `update_many` /
23 /// `delete_many` build one per matched row.
24 pub audit_events: Vec<AuditEvent>,
25}
26
27impl<T> RunInTxOutcome<T> {
28 pub(crate) fn new(value: T, audit_events: Vec<AuditEvent>) -> Self {
29 Self {
30 value,
31 audit_events,
32 }
33 }
34}