Check for and fire INSTEAD OF triggers for an INSERT operation. Returns `InsteadOfResult::Handled` if an INSTEAD OF trigger fired (caller must skip normal dispatch). Returns `NoTrigger` otherwise.
(
state: &SharedState,
identity: &AuthenticatedIdentity,
tenant_id: TenantId,
collection: &str,
new_fields: &HashMap<String, nodedb_types::Value>,
cascade_depth: u32,
)
| 36 | /// Returns `InsteadOfResult::Handled` if an INSTEAD OF trigger fired |
| 37 | /// (caller must skip normal dispatch). Returns `NoTrigger` otherwise. |
| 38 | pub async fn fire_instead_of_insert( |
| 39 | state: &SharedState, |
| 40 | identity: &AuthenticatedIdentity, |
| 41 | tenant_id: TenantId, |
| 42 | collection: &str, |
| 43 | new_fields: &HashMap<String, nodedb_types::Value>, |
| 44 | cascade_depth: u32, |
| 45 | ) -> crate::Result<InsteadOfResult> { |
| 46 | let triggers = |
| 47 | state |
| 48 | .trigger_registry |
| 49 | .get_matching(tenant_id.as_u64(), collection, DmlEvent::Insert); |
| 50 | |
| 51 | let instead_triggers: Vec<_> = triggers |
| 52 | .into_iter() |
| 53 | .filter(|t| t.timing == TriggerTiming::InsteadOf) |
| 54 | .collect(); |
| 55 | |
| 56 | if instead_triggers.is_empty() { |
| 57 | return Ok(InsteadOfResult::NoTrigger); |
| 58 | } |
| 59 | |
| 60 | check_cascade_depth(cascade_depth, collection)?; |
| 61 | |
| 62 | let bindings = RowBindings::before_insert(collection, new_fields.clone()); |
| 63 | |
| 64 | fire_triggers( |
| 65 | state, |
| 66 | identity, |
| 67 | tenant_id, |
| 68 | collection, |
| 69 | &instead_triggers, |
| 70 | &bindings, |
| 71 | cascade_depth, |
| 72 | ) |
| 73 | .await?; |
| 74 | |
| 75 | Ok(InsteadOfResult::Handled) |
| 76 | } |
| 77 | |
| 78 | /// Check for and fire INSTEAD OF triggers for an UPDATE operation. |
| 79 | #[allow(clippy::too_many_arguments)] |
no test coverage detected