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

Function fire_instead_of_insert

nodedb/src/control/trigger/fire_instead.rs:38–76  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

36/// Returns `InsteadOfResult::Handled` if an INSTEAD OF trigger fired
37/// (caller must skip normal dispatch). Returns `NoTrigger` otherwise.
38pub 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)]

Callers 2

fire_instead_triggersFunction · 0.85

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