Skip to main content

sqlite_diff_rs/builders/
format.rs

1//! Format trait defining changeset vs patchset behavior.
2
3use crate::encoding::{MaybeValue, Value};
4use alloc::vec::Vec;
5use core::fmt::Debug;
6
7/// Trait defining the differences between changeset and patchset formats.
8///
9/// A changeset DELETE stores all column values and a changeset UPDATE stores
10/// both old and new values. A patchset DELETE stores only the PK (data lives
11/// externally) and a patchset UPDATE stores only the PK plus new values.
12pub(crate) trait Format<S, B>: Default + Clone + Copy + PartialEq + Eq + 'static {
13    /// The type representing old values in this format.
14    ///
15    /// - Changeset: `MaybeValue<S, B>` (Option<Value<S, B>>, None = undefined/unchanged)
16    /// - Patchset: `()` (old values not stored)
17    type Old: Clone + Debug + Default;
18
19    /// The data stored for a DELETE operation (beyond the PK which is always
20    /// stored as the `IndexMap` key in `DiffSetBuilder`).
21    ///
22    /// - Changeset: `Vec<Value<S, B>>` (full old-row values)
23    /// - Patchset: `()` (only the PK matters, stored externally)
24    type DeleteData: Clone + Debug + Default;
25}
26
27/// Changeset format marker.
28#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
29pub struct ChangesetFormat;
30
31impl<S: Clone + Debug + AsRef<str>, B: Clone + Debug + AsRef<[u8]>> Format<S, B>
32    for ChangesetFormat
33{
34    type Old = MaybeValue<S, B>;
35    type DeleteData = Vec<Value<S, B>>;
36}
37
38/// Patchset format marker.
39#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
40pub struct PatchsetFormat;
41
42impl<S, B> Format<S, B> for PatchsetFormat {
43    type Old = ();
44    type DeleteData = ();
45}