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

Function fire_pre_dispatch_triggers

nodedb/src/control/trigger/dml_hook_fire.rs:41–165  ·  view source on GitHub ↗
(
    state: &SharedState,
    identity: &AuthenticatedIdentity,
    tenant_id: TenantId,
    info: &DmlWriteInfo,
    old_row: &Option<HashMap<String, nodedb_types::Value>>,
    cascade_depth: u32,
)

Source from the content-addressed store, hash-verified

39/// the caller should abort the write.
40#[allow(clippy::too_many_arguments)]
41pub async fn fire_pre_dispatch_triggers(
42 state: &SharedState,
43 identity: &AuthenticatedIdentity,
44 tenant_id: TenantId,
45 info: &DmlWriteInfo,
46 old_row: &Option<HashMap<String, nodedb_types::Value>>,
47 cascade_depth: u32,
48) -> crate::Result<PreDispatchResult> {
49 // Check INSTEAD OF first — if it handles the write, skip everything else.
50 match info.event {
51 DmlEvent::Insert => {
52 if let Some(ref new_fields) = info.new_fields {
53 match super::fire_instead::fire_instead_of_insert(
54 state,
55 identity,
56 tenant_id,
57 &info.collection,
58 new_fields,
59 cascade_depth,
60 )
61 .await?
62 {
63 InsteadOfResult::Handled => return Ok(PreDispatchResult::Handled),
64 InsteadOfResult::NoTrigger => {}
65 }
66 }
67 }
68 DmlEvent::Update => {
69 let empty = HashMap::new();
70 let old_fields = old_row.as_ref().unwrap_or(&empty);
71 let new_fields = info.new_fields.as_ref().unwrap_or(&empty);
72 match super::fire_instead::fire_instead_of_update(
73 state,
74 identity,
75 tenant_id,
76 &info.collection,
77 old_fields,
78 new_fields,
79 cascade_depth,
80 )
81 .await?
82 {
83 InsteadOfResult::Handled => return Ok(PreDispatchResult::Handled),
84 InsteadOfResult::NoTrigger => {}
85 }
86 }
87 DmlEvent::Delete => {
88 let empty = HashMap::new();
89 let old_fields = old_row.as_ref().unwrap_or(&empty);
90 match super::fire_instead::fire_instead_of_delete(
91 state,
92 identity,
93 tenant_id,
94 &info.collection,
95 old_fields,
96 cascade_depth,
97 )
98 .await?

Callers 1

dispatch_task_loopMethod · 0.85

Calls 7

fire_instead_of_insertFunction · 0.85
fire_instead_of_updateFunction · 0.85
fire_instead_of_deleteFunction · 0.85
fire_before_insertFunction · 0.85
fire_before_updateFunction · 0.85
fire_before_deleteFunction · 0.85
as_refMethod · 0.45

Tested by

no test coverage detected