pub struct ObserverDefinition {
pub name: String,
pub entity: String,
pub event: String,
pub condition: Option<String>,
pub actions: Vec<Value>,
pub retry: RetryConfig,
}Expand description
Observer definition - database change event listener.
Observers trigger actions (webhooks, notifications) when database changes occur, enabling event-driven architectures.
§Example
use fraiseql_core::schema::{ObserverDefinition, RetryConfig};
let observer = ObserverDefinition {
name: "onHighValueOrder".to_string(),
entity: "Order".to_string(),
event: "INSERT".to_string(),
condition: Some("total > 1000".to_string()),
actions: vec![
serde_json::json!({
"type": "webhook",
"url": "https://api.example.com/high-value-orders"
}),
],
retry: RetryConfig {
max_attempts: 3,
backoff_strategy: "exponential".to_string(),
initial_delay_ms: 1000,
max_delay_ms: 60000,
},
};Fields§
§name: StringObserver name (unique identifier).
entity: StringEntity type to observe (e.g., “Order”, “User”).
event: StringEvent type: INSERT, UPDATE, or DELETE.
condition: Option<String>Optional condition expression in FraiseQL DSL. Example: “total > 1000” or “status.changed() and status == ‘shipped’”
actions: Vec<Value>Actions to execute when observer triggers. Each action is a JSON object with a “type” field (webhook, slack, email).
retry: RetryConfigRetry configuration for action execution.
Implementations§
Source§impl ObserverDefinition
impl ObserverDefinition
Sourcepub fn new(
name: impl Into<String>,
entity: impl Into<String>,
event: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, entity: impl Into<String>, event: impl Into<String>, ) -> Self
Create a new observer definition.
Sourcepub fn with_condition(self, condition: impl Into<String>) -> Self
pub fn with_condition(self, condition: impl Into<String>) -> Self
Set the condition expression.
Sourcepub fn with_action(self, action: Value) -> Self
pub fn with_action(self, action: Value) -> Self
Add an action to this observer.
Sourcepub fn with_actions(self, actions: Vec<Value>) -> Self
pub fn with_actions(self, actions: Vec<Value>) -> Self
Add multiple actions to this observer.
Sourcepub fn with_retry(self, retry: RetryConfig) -> Self
pub fn with_retry(self, retry: RetryConfig) -> Self
Set the retry configuration.
Sourcepub fn has_condition(&self) -> bool
pub fn has_condition(&self) -> bool
Check if this observer has a condition.
Sourcepub fn action_count(&self) -> usize
pub fn action_count(&self) -> usize
Get the number of actions.
Trait Implementations§
Source§impl Clone for ObserverDefinition
impl Clone for ObserverDefinition
Source§fn clone(&self) -> ObserverDefinition
fn clone(&self) -> ObserverDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more