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