1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Module: db::write_context
//! Responsibility: canonical mutation mode and durable operation-time context.
//! Does not own: application normalization, validation, or accepted write policy.
//! Boundary: frontend mutation intent -> accepted after-image resolution.
use crate::types::Timestamp;
///
/// MutationMode
///
/// Exact row-existence contract selected for one database mutation.
///
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MutationMode {
/// Insert only when the target row is absent.
Insert,
/// Replace either an absent or existing target row.
Replace,
/// Update only when the target row exists.
Update,
}
///
/// AcceptedWriteContext
///
/// Database-owned operation facts frozen before accepted after-image
/// resolution. Application normalizers and validators never receive this
/// context.
///
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(in crate::db) struct AcceptedWriteContext {
mode: MutationMode,
operation_timestamp: Timestamp,
}
impl AcceptedWriteContext {
/// Build one accepted write context from frontend-frozen operation facts.
#[must_use]
pub(in crate::db) const fn new(mode: MutationMode, operation_timestamp: Timestamp) -> Self {
Self {
mode,
operation_timestamp,
}
}
/// Return the exact database mutation mode.
#[must_use]
pub(in crate::db) const fn mode(self) -> MutationMode {
self.mode
}
/// Return the durable timestamp shared by the logical operation.
#[must_use]
pub(in crate::db) const fn operation_timestamp(self) -> Timestamp {
self.operation_timestamp
}
}