surrealdb_core/sql/
changefeed.rs

1use crate::sql::duration::Duration;
2use crate::sql::statements::info::InfoStructure;
3use crate::sql::Value;
4use revision::revisioned;
5use serde::{Deserialize, Serialize};
6use std::fmt::{self, Display, Formatter};
7use std::str;
8use std::time;
9
10#[revisioned(revision = 2)]
11#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
12#[non_exhaustive]
13pub struct ChangeFeed {
14	pub expiry: time::Duration,
15	#[revision(start = 2)]
16	pub store_diff: bool,
17}
18impl Display for ChangeFeed {
19	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
20		write!(f, "CHANGEFEED {}", Duration(self.expiry))?;
21		if self.store_diff {
22			write!(f, " INCLUDE ORIGINAL")?;
23		};
24		Ok(())
25	}
26}
27
28impl Default for ChangeFeed {
29	fn default() -> Self {
30		Self {
31			expiry: time::Duration::from_secs(0),
32			store_diff: false,
33		}
34	}
35}
36
37impl InfoStructure for ChangeFeed {
38	fn structure(self) -> Value {
39		Value::from(map! {
40			"expiry".to_string() => Duration(self.expiry).structure(),
41			"original".to_string() => self.store_diff.into(),
42		})
43	}
44}