MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / fire_before_delete

Function fire_before_delete

nodedb/src/control/trigger/fire_before.rs:127–163  ·  view source on GitHub ↗

Fire BEFORE ROW triggers for a DELETE operation. BEFORE DELETE triggers cannot modify the row (there is no NEW). They can only validate and reject via RAISE EXCEPTION, or execute side-effect DML. If a trigger raises an exception, the DELETE is aborted.

(
    state: &SharedState,
    identity: &AuthenticatedIdentity,
    tenant_id: TenantId,
    collection: &str,
    old_fields: &HashMap<String, nodedb_types::Value>,
    cascade_depth: u32,
)

Source from the content-addressed store, hash-verified

125///
126/// If a trigger raises an exception, the DELETE is aborted.
127pub async fn fire_before_delete(
128 state: &SharedState,
129 identity: &AuthenticatedIdentity,
130 tenant_id: TenantId,
131 collection: &str,
132 old_fields: &HashMap<String, nodedb_types::Value>,
133 cascade_depth: u32,
134) -> crate::Result<()> {
135 let triggers =
136 state
137 .trigger_registry
138 .get_matching(tenant_id.as_u64(), collection, DmlEvent::Delete);
139
140 let before_triggers: Vec<_> = triggers
141 .into_iter()
142 .filter(|t| t.timing == TriggerTiming::Before)
143 .collect();
144
145 if before_triggers.is_empty() {
146 return Ok(());
147 }
148
149 check_cascade_depth(cascade_depth, collection)?;
150
151 let bindings = RowBindings::before_delete(collection, old_fields.clone());
152
153 fire_triggers(
154 state,
155 identity,
156 tenant_id,
157 collection,
158 &before_triggers,
159 &bindings,
160 cascade_depth,
161 )
162 .await
163}

Callers 1

Calls 7

check_cascade_depthFunction · 0.85
fire_triggersFunction · 0.85
get_matchingMethod · 0.80
collectMethod · 0.80
as_u64Method · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected