Skip to main content

DiffSetBuilder

Struct DiffSetBuilder 

Source
pub struct DiffSetBuilder<F: Format<S, B>, T: SchemaWithPK, S, B> { /* private fields */ }
Expand description

Builder for constructing changeset or patchset binary data.

DiffSetBuilder tracks rows in DML insertion order. When build is called, it simulates SQLite’s session-extension hash table to produce byte-identical output.

For parsed (frozen) data that should be emitted in its original order, see DiffSet.

Generic over the format F (Changeset or Patchset), table schema T, and value types S, B.

Implementations§

Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: AsRef<str> + Hash + Eq, B: AsRef<[u8]> + Hash + Eq> DiffSetBuilder<F, T, S, B>

Source

pub fn new() -> Self

Create a new builder.

Source

pub fn add_table(&mut self, table: &T) -> &mut Self

Register a table schema without adding any operations.

This is useful when you need the table present (e.g. before calling DiffSetBuilder::digest_sql) but don’t have operations yet. If the table is already registered, this is a no-op.

Source

pub fn is_empty(&self) -> bool

Returns true if the builder has no operations.

Source

pub fn len(&self) -> usize

Returns the number of operations across all tables.

Source§

impl<T: NamedColumns, S: Clone + Hash + Eq + AsRef<str> + for<'a> From<&'a str>> DiffSetBuilder<PatchsetFormat, T, S, Vec<u8>>

Source

pub fn digest_sql<'input>( &mut self, input: &'input str, ) -> Result<&mut Self, ParseError<'input>>

Digest a SQL string containing INSERT, UPDATE, and DELETE statements into this patchset builder.

The SQL statements are parsed and their effects are directly applied to the builder, consolidating operations by primary key as usual.

§Errors

Returns a crate::builders::sql::ParseError if the SQL cannot be parsed.

Source§

impl<T: SchemaWithPK, S: Clone + Debug + Hash + Eq + AsRef<str>, B: Clone + Debug + Hash + Eq + AsRef<[u8]>> DiffSetBuilder<ChangesetFormat, T, S, B>

Source

pub fn build(&self) -> Vec<u8>

Build the changeset binary data.

Returns the binary representation compatible with SQLite’s session extension.

§Panics

This function does not panic under normal usage. Internal indexing is guaranteed to be within bounds.

Source§

impl<T: SchemaWithPK, S: Clone + Debug + AsRef<str>, B: Clone + Debug + AsRef<[u8]>> DiffSetBuilder<ChangesetFormat, T, S, B>

Source

pub fn iter(&self) -> impl Iterator<Item = ChangesetOp<'_, T, S, B>>

Walk operations grouped by table in DML insertion order.

Mirrors DiffSet::iter but keeps insertion order; the session-extension hash ordering only applies at build time.

Source§

impl<T: SchemaWithPK, S: Clone + Hash + Eq + AsRef<str>, B: Clone + Hash + Eq + AsRef<[u8]>> DiffSetBuilder<PatchsetFormat, T, S, B>

Source

pub fn build(&self) -> Vec<u8>

Build the patchset binary data.

Returns the binary representation compatible with SQLite’s session extension.

§Panics

This function does not panic under normal usage. Internal indexing is guaranteed to be within bounds.

Source§

impl<T: SchemaWithPK, S: Clone + AsRef<str>, B: Clone + AsRef<[u8]>> DiffSetBuilder<PatchsetFormat, T, S, B>

Source

pub fn iter(&self) -> impl Iterator<Item = PatchsetOp<'_, T, S, B>>

Walk operations grouped by table in DML insertion order.

Mirrors DiffSet::iter but keeps insertion order; the session-extension hash ordering only applies at build time. With the diesel feature enabled, each item implements QueryFragment and executes via RunQueryDsl.

Source§

impl<T: ColumnNames, S: AsRef<str> + Clone + Debug + Hash + Eq, B: AsRef<[u8]> + Clone + Debug + Hash + Eq> DiffSetBuilder<ChangesetFormat, T, S, B>

Source

pub fn sql_statements(&self) -> impl Iterator<Item = String> + '_

Iterate over operations as SQL statements.

Each operation is converted to an INSERT, UPDATE, or DELETE statement. Identifiers (table and column names) are quoted with double quotes. Statements do not include trailing semicolons.

§Example
use sqlite_diff_rs::{SimpleTable, ChangeSet, DiffOps, Insert};

let table = SimpleTable::new("users", &["id", "name"], &[0]);
let insert = Insert::from(table.clone())
    .set(0, 1i64).unwrap()
    .set(1, "Alice").unwrap();

let changeset = ChangeSet::<SimpleTable, String, Vec<u8>>::new().insert(insert);

for sql in changeset.sql_statements() {
    assert_eq!(sql, r#"INSERT INTO "users" ("id", "name") VALUES (1, 'Alice')"#);
}
Source§

impl<T: ColumnNames, S: AsRef<str> + Clone + Hash + Eq, B: AsRef<[u8]> + Clone + Hash + Eq> DiffSetBuilder<PatchsetFormat, T, S, B>

Source

pub fn sql_statements(&self) -> impl Iterator<Item = String> + '_

Iterate over operations as SQL statements.

Each operation is converted to an INSERT, UPDATE, or DELETE statement. Identifiers (table and column names) are quoted with double quotes. Statements do not include trailing semicolons.

§Example
use sqlite_diff_rs::{SimpleTable, PatchSet, DiffOps, Insert};

let table = SimpleTable::new("users", &["id", "name"], &[0]);
let insert = Insert::from(table.clone())
    .set(0, 1i64).unwrap()
    .set(1, "Alice").unwrap();

let patchset = PatchSet::<SimpleTable, String, Vec<u8>>::new().insert(insert);

for sql in patchset.sql_statements() {
    assert_eq!(sql, r#"INSERT INTO "users" ("id", "name") VALUES (1, 'Alice')"#);
}

Trait Implementations§

Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: Clone + Hash + Eq + AsRef<str>, B: Clone + Hash + Eq + AsRef<[u8]>> BitOr for DiffSetBuilder<F, T, S, B>
where Operation<F, S, B>: Add<Output = Option<Operation<F, S, B>>>,

Source§

fn bitor(self, rhs: Self) -> Self::Output

Merge two diff sets, consolidating operations on the same row.

Source§

type Output = DiffSetBuilder<F, T, S, B>

The resulting type after applying the | operator.
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: Clone + Hash + Eq + AsRef<str>, B: Clone + Hash + Eq + AsRef<[u8]>> BitOrAssign for DiffSetBuilder<F, T, S, B>
where Operation<F, S, B>: Add<Output = Option<Operation<F, S, B>>>,

Source§

fn bitor_assign(&mut self, rhs: Self)

Merge another diff set into this one, consolidating operations on the same row.

Source§

impl<F: Clone + Format<S, B>, T: Clone + SchemaWithPK, S: Clone, B: Clone> Clone for DiffSetBuilder<F, T, S, B>

Source§

fn clone(&self) -> DiffSetBuilder<F, T, S, B>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Format<S, B>, T: Debug + SchemaWithPK, S: Debug, B: Debug> Debug for DiffSetBuilder<F, T, S, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: AsRef<str> + Hash + Eq, B: AsRef<[u8]> + Hash + Eq> Default for DiffSetBuilder<F, T, S, B>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: SchemaWithPK, S: Clone + Debug + Hash + Eq + AsRef<str>, B: Clone + Debug + Hash + Eq + AsRef<[u8]>> DiffOps<T, S, B> for DiffSetBuilder<ChangesetFormat, T, S, B>

Source§

type Format = ChangesetFormat

The format (changeset or patchset) of the diff set.
Source§

type DeleteArg = ChangeDelete<T, S, B>

The argument type for the delete operation. Read more
Source§

fn insert(self, insert: Insert<T, S, B>) -> Self

Add an INSERT operation.
Source§

fn delete(self, delete: ChangeDelete<T, S, B>) -> Self

Add a DELETE operation.
Source§

fn update(self, update: Update<T, ChangesetFormat, S, B>) -> Self

Add an UPDATE operation.
Source§

impl<T: SchemaWithPK, S: Clone + Hash + Eq + AsRef<str>, B: Clone + Hash + Eq + AsRef<[u8]>> DiffOps<T, S, B> for DiffSetBuilder<PatchsetFormat, T, S, B>

Source§

fn delete(self, delete: PatchDelete<T, S, B>) -> Self

Delete by primary key.

§Example
use sqlite_diff_rs::{DiffOps, PatchDelete, PatchSet, SchemaWithPK, TableSchema};

// CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)
let schema: TableSchema<String> = TableSchema::new("users".into(), 2, vec![1, 0]);

// Delete row where id = 1
let patchset = PatchSet::<_, String, Vec<u8>>::new()
    .delete(PatchDelete::new(schema, vec![1i64.into()]));
Source§

fn update(self, update: Update<T, PatchsetFormat, S, B>) -> Self

Update by primary key.

§Example
use sqlite_diff_rs::{DiffOps, PatchSet, PatchsetFormat, Update, TableSchema};

// CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)
let schema: TableSchema<String> = TableSchema::new("users".into(), 2, vec![1, 0]);

// UPDATE users SET name = 'Bob' WHERE id = 1
let update = Update::<_, PatchsetFormat, String, Vec<u8>>::from(schema)
    .set(0, 1i64).unwrap()  // PK value
    .set(1, "Bob").unwrap();

let patchset = PatchSet::<_, String, Vec<u8>>::new()
    .update(update);
Source§

type Format = PatchsetFormat

The format (changeset or patchset) of the diff set.
Source§

type DeleteArg = PatchDelete<T, S, B>

The argument type for the delete operation. Read more
Source§

fn insert(self, insert: Insert<T, S, B>) -> Self

Add an INSERT operation.
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S, B> Eq for DiffSetBuilder<F, T, S, B>
where S: Eq + Hash + AsRef<str>, B: Eq + Hash + AsRef<[u8]>, F::Old: Eq, F::DeleteData: Eq,

Source§

impl<T: SchemaWithPK, S: Clone + Debug + Hash + Eq + AsRef<str>, B: Clone + Debug + Hash + Eq + AsRef<[u8]>> From<&DiffSetBuilder<ChangesetFormat, T, S, B>> for Vec<u8>

Source§

fn from(builder: &DiffSetBuilder<ChangesetFormat, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: SchemaWithPK, S: AsRef<str> + Clone + Hash + Eq, B: AsRef<[u8]> + Clone + Hash + Eq> From<&DiffSetBuilder<PatchsetFormat, T, S, B>> for Vec<u8>

Source§

fn from(builder: &DiffSetBuilder<PatchsetFormat, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: Hash + Eq + AsRef<str>, B: Hash + Eq + AsRef<[u8]>> From<DiffSet<F, T, S, B>> for DiffSetBuilder<F, T, S, B>

Source§

fn from(diffset: DiffSet<F, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: SchemaWithPK, S: Clone + Debug + Hash + Eq + AsRef<str>, B: Clone + Debug + Hash + Eq + AsRef<[u8]>> From<DiffSetBuilder<ChangesetFormat, T, S, B>> for Vec<u8>

Source§

fn from(builder: DiffSetBuilder<ChangesetFormat, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S: Hash + Eq + AsRef<str>, B: Hash + Eq + AsRef<[u8]>> From<DiffSetBuilder<F, T, S, B>> for DiffSet<F, T, S, B>

Source§

fn from(builder: DiffSetBuilder<F, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: SchemaWithPK, S: AsRef<str> + Clone + Hash + Eq, B: AsRef<[u8]> + Clone + Hash + Eq> From<DiffSetBuilder<PatchsetFormat, T, S, B>> for Vec<u8>

Source§

fn from(builder: DiffSetBuilder<PatchsetFormat, T, S, B>) -> Self

Converts to this type from the input type.
Source§

impl<F: Format<S, B>, T: SchemaWithPK, S, B> PartialEq for DiffSetBuilder<F, T, S, B>
where S: PartialEq + Eq + Hash + AsRef<str>, B: PartialEq + Eq + Hash + AsRef<[u8]>, F::Old: PartialEq, F::DeleteData: PartialEq,

Custom PartialEq that ignores tables with empty operations.

Tables with no operations are not serialized (skipped in build()), so after roundtrip they won’t exist. This makes empty tables semantically equivalent to non-existent tables for comparison purposes.

Verified: SQLite’s session extension does NOT include empty table entries in changesets/patchsets when all operations cancel out. Our builder keeps them in memory to preserve table ordering, but they are correctly excluded here and in build().

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: SchemaWithPK, S: Clone + Debug + Hash + Eq + AsRef<str>, B: Clone + Debug + Hash + Eq + AsRef<[u8]>> Reverse for DiffSetBuilder<ChangesetFormat, T, S, B>

Source§

type Output = DiffSetBuilder<ChangesetFormat, T, S, B>

The reverse of this operation.
Source§

fn reverse(self) -> Self::Output

Returns the reverse of this operation.

Auto Trait Implementations§

§

impl<F, T, S, B> Freeze for DiffSetBuilder<F, T, S, B>

§

impl<F, T, S, B> RefUnwindSafe for DiffSetBuilder<F, T, S, B>
where T: RefUnwindSafe, <F as Format<S, B>>::DeleteData: RefUnwindSafe, S: RefUnwindSafe, B: RefUnwindSafe, <F as Format<S, B>>::Old: RefUnwindSafe,

§

impl<F, T, S, B> Send for DiffSetBuilder<F, T, S, B>
where T: Send, <F as Format<S, B>>::DeleteData: Send, S: Send, B: Send, <F as Format<S, B>>::Old: Send,

§

impl<F, T, S, B> Sync for DiffSetBuilder<F, T, S, B>
where T: Sync, <F as Format<S, B>>::DeleteData: Sync, S: Sync, B: Sync, <F as Format<S, B>>::Old: Sync,

§

impl<F, T, S, B> Unpin for DiffSetBuilder<F, T, S, B>
where T: Unpin, <F as Format<S, B>>::DeleteData: Unpin, S: Unpin, B: Unpin, <F as Format<S, B>>::Old: Unpin,

§

impl<F, T, S, B> UnsafeUnpin for DiffSetBuilder<F, T, S, B>

§

impl<F, T, S, B> UnwindSafe for DiffSetBuilder<F, T, S, B>
where T: UnwindSafe, <F as Format<S, B>>::DeleteData: UnwindSafe, S: UnwindSafe, B: UnwindSafe, <F as Format<S, B>>::Old: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.