ChangeTrackingQuery

Struct ChangeTrackingQuery 

Source
pub struct ChangeTrackingQuery { /* private fields */ }
Expand description

Query builder for Change Tracking operations.

Helps construct proper SQL queries for common Change Tracking patterns.

§Example

use mssql_client::change_tracking::ChangeTrackingQuery;

// Query for all changes since version 42
let query = ChangeTrackingQuery::changes("Products", 42);
assert!(query.to_sql().contains("CHANGETABLE"));

// Query with specific columns
let query = ChangeTrackingQuery::changes("Orders", 100)
    .with_columns(&["OrderId", "CustomerId", "OrderDate"]);
let sql = query.to_sql();
assert!(sql.contains("OrderId"));

Implementations§

Source§

impl ChangeTrackingQuery

Source

pub fn changes(table_name: impl Into<String>, last_sync_version: i64) -> Self

Create a query for changes to a table since a specific version.

This generates a CHANGETABLE(CHANGES table_name, last_sync_version) query.

§Arguments
  • table_name - The name of the table to query changes for
  • last_sync_version - The version from the previous sync (0 for initial)
§Example
use mssql_client::change_tracking::ChangeTrackingQuery;

let query = ChangeTrackingQuery::changes("Products", 42);
Source

pub fn with_columns(self, columns: &[&str]) -> Self

Specify which data columns to include (in addition to change tracking columns).

If not specified, only change tracking system columns are returned.

§Arguments
  • columns - Column names to include in the result
Source

pub fn with_primary_keys(self, keys: &[&str]) -> Self

Specify the primary key columns for the table.

This is needed when you want to join change tracking results with the original table to get current row data.

Source

pub fn with_alias(self, alias: impl Into<String>) -> Self

Set the table alias for the CHANGETABLE result.

Source

pub fn with_force_seek(self) -> Self

Enable FORCESEEK hint for the query.

This can improve performance in some scenarios.

Source

pub fn to_sql(&self) -> String

Generate the SQL query string.

This returns a query that can be executed directly.

Source

pub fn to_sql_with_data(&self, data_columns: &[&str]) -> String

Generate a SQL query that joins with the original table.

This is useful when you need both the change tracking metadata and the current row data (for inserts and updates).

§Arguments
  • data_columns - Columns from the data table to include
§Example
use mssql_client::change_tracking::ChangeTrackingQuery;

let query = ChangeTrackingQuery::changes("Products", 42)
    .with_primary_keys(&["ProductId"]);
let sql = query.to_sql_with_data(&["Name", "Price", "Stock"]);
assert!(sql.contains("LEFT OUTER JOIN"));

Trait Implementations§

Source§

impl Clone for ChangeTrackingQuery

Source§

fn clone(&self) -> ChangeTrackingQuery

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ChangeTrackingQuery

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more