Skip to main content

kurrentdb/options/
projections.rs

1use kurrentdb_macros::options;
2
3/// Selects which projection engine the server should use when creating a
4/// continuous projection. `V1` is the default and is supported by every server
5/// version. `V2` requires a server that supports the next-generation engine.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub enum ProjectionEngineVersion {
8    #[default]
9    V1,
10    V2,
11}
12
13impl ProjectionEngineVersion {
14    pub(crate) fn as_i32(self) -> i32 {
15        match self {
16            ProjectionEngineVersion::V1 => 1,
17            ProjectionEngineVersion::V2 => 2,
18        }
19    }
20}
21
22options! {
23    #[derive(Clone, Default)]
24    pub struct CreateProjectionOptions {
25        pub(crate) track_emitted_streams: bool,
26        pub(crate) emit: bool,
27        pub(crate) engine_version: ProjectionEngineVersion,
28    }
29}
30
31impl CreateProjectionOptions {
32    pub fn new() -> Self {
33        Default::default()
34    }
35
36    pub fn track_emitted_streams(self, track_emitted_streams: bool) -> Self {
37        Self {
38            track_emitted_streams,
39            ..self
40        }
41    }
42
43    pub fn emit(self, emit: bool) -> Self {
44        Self { emit, ..self }
45    }
46
47    pub fn engine_version(self, engine_version: ProjectionEngineVersion) -> Self {
48        Self {
49            engine_version,
50            ..self
51        }
52    }
53}
54
55options! {
56    #[derive(Clone, Default)]
57    pub struct UpdateProjectionOptions {
58        pub(crate) emit: Option<bool>,
59    }
60}
61
62impl UpdateProjectionOptions {
63    pub fn new() -> Self {
64        Default::default()
65    }
66
67    pub fn emit(self, emit: bool) -> Self {
68        Self {
69            emit: Some(emit),
70            ..self
71        }
72    }
73}
74
75options! {
76    #[derive(Clone, Default)]
77    pub struct DeleteProjectionOptions {
78        pub(crate) delete_emitted_streams: bool,
79        pub(crate) delete_state_stream: bool,
80        pub(crate) delete_checkpoint_stream: bool,
81    }
82}
83
84impl DeleteProjectionOptions {
85    pub fn new() -> Self {
86        Default::default()
87    }
88
89    pub fn delete_emitted_streams(self, delete_emitted_streams: bool) -> Self {
90        Self {
91            delete_emitted_streams,
92            ..self
93        }
94    }
95
96    pub fn delete_state_stream(self, delete_state_stream: bool) -> Self {
97        Self {
98            delete_state_stream,
99            ..self
100        }
101    }
102
103    pub fn delete_checkpoint_stream(self, delete_checkpoint_stream: bool) -> Self {
104        Self {
105            delete_checkpoint_stream,
106            ..self
107        }
108    }
109}
110
111options! {
112    #[derive(Clone, Default)]
113    pub struct GetStateProjectionOptions {
114        pub(crate) partition: String,
115    }
116}
117
118impl GetStateProjectionOptions {
119    pub fn new() -> Self {
120        Default::default()
121    }
122
123    pub fn partition(self, value: impl AsRef<str>) -> Self {
124        Self {
125            partition: value.as_ref().to_string(),
126            ..self
127        }
128    }
129}
130
131options! {
132    #[derive(Clone, Default)]
133    pub struct GetResultProjectionOptions {
134        pub(crate) partition: String,
135    }
136}
137
138impl GetResultProjectionOptions {
139    pub fn new() -> Self {
140        Default::default()
141    }
142
143    pub fn partition(self, value: impl AsRef<str>) -> Self {
144        Self {
145            partition: value.as_ref().to_string(),
146            ..self
147        }
148    }
149}
150
151options! {
152    #[derive(Clone, Default)]
153    pub struct GenericProjectionOptions {}
154}