surrealdb_core/dbs/
notification.rs1#[cfg(test)]
2use crate::dbs::fuzzy_eq::FuzzyEq;
3use crate::sql::{Object, Uuid, Value};
4use revision::revisioned;
5use serde::{Deserialize, Serialize};
6use std::fmt::{self, Debug, Display};
7
8#[revisioned(revision = 1)]
9#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "UPPERCASE")]
11#[non_exhaustive]
12pub enum Action {
13 Create,
14 Update,
15 Delete,
16}
17
18impl Display for Action {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 match *self {
21 Action::Create => write!(f, "CREATE"),
22 Action::Update => write!(f, "UPDATE"),
23 Action::Delete => write!(f, "DELETE"),
24 }
25 }
26}
27
28#[revisioned(revision = 1)]
29#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
30#[non_exhaustive]
31pub struct Notification {
32 pub id: Uuid,
34 pub action: Action,
36 pub record: Value,
38 pub result: Value,
40}
41
42impl Display for Notification {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 let obj: Object = map! {
45 "id".to_string() => self.id.to_string().into(),
46 "action".to_string() => self.action.to_string().into(),
47 "record".to_string() => self.record.clone(),
48 "result".to_string() => self.result.clone(),
49 }
50 .into();
51 write!(f, "{}", obj)
52 }
53}
54
55impl Notification {
56 pub const fn new(id: Uuid, action: Action, record: Value, result: Value) -> Self {
58 Self {
59 id,
60 action,
61 record,
62 result,
63 }
64 }
65}
66
67#[cfg(test)]
68impl FuzzyEq for Notification {
69 fn fuzzy_eq(&self, other: &Self) -> bool {
70 self.action == other.action && self.record == other.record && self.result == other.result
71 }
72}