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 const fn has_condition(&self) -> bool
pub const fn has_condition(&self) -> bool
Check if this observer has a condition.
Sourcepub const fn action_count(&self) -> usize
pub const 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 moreSource§impl Debug for ObserverDefinition
impl Debug for ObserverDefinition
Source§impl<'de> Deserialize<'de> for ObserverDefinition
impl<'de> Deserialize<'de> for ObserverDefinition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ObserverDefinition
impl PartialEq for ObserverDefinition
Source§impl Serialize for ObserverDefinition
impl Serialize for ObserverDefinition
impl Eq for ObserverDefinition
impl StructuralPartialEq for ObserverDefinition
Auto Trait Implementations§
impl Freeze for ObserverDefinition
impl RefUnwindSafe for ObserverDefinition
impl Send for ObserverDefinition
impl Sync for ObserverDefinition
impl Unpin for ObserverDefinition
impl UnsafeUnpin for ObserverDefinition
impl UnwindSafe for ObserverDefinition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more