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
impl ChangeTrackingQuery
Sourcepub fn changes(table_name: impl Into<String>, last_sync_version: i64) -> Self
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 forlast_sync_version- The version from the previous sync (0 for initial)
§Example
use mssql_client::change_tracking::ChangeTrackingQuery;
let query = ChangeTrackingQuery::changes("Products", 42);Sourcepub fn with_columns(self, columns: &[&str]) -> Self
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
Sourcepub fn with_primary_keys(self, keys: &[&str]) -> Self
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.
Sourcepub fn with_alias(self, alias: impl Into<String>) -> Self
pub fn with_alias(self, alias: impl Into<String>) -> Self
Set the table alias for the CHANGETABLE result.
Sourcepub fn with_force_seek(self) -> Self
pub fn with_force_seek(self) -> Self
Enable FORCESEEK hint for the query.
This can improve performance in some scenarios.
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Generate the SQL query string.
This returns a query that can be executed directly.
Sourcepub fn to_sql_with_data(&self, data_columns: &[&str]) -> String
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
impl Clone for ChangeTrackingQuery
Source§fn clone(&self) -> ChangeTrackingQuery
fn clone(&self) -> ChangeTrackingQuery
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more