Skip to main content

Crate drasi_source_mssql

Crate drasi_source_mssql 

Source
Expand description

Microsoft SQL Server CDC Source for Drasi

This source plugin captures data changes from MS SQL Server databases using Change Data Capture (CDC). It monitors CDC change tables and converts changes to Drasi source events.

§Features

  • Real-time change capture via CDC polling
  • LSN-based progress tracking with StateStore persistence
  • Automatic LSN validation and recovery
  • Support for INSERT, UPDATE, DELETE operations
  • Transaction grouping
  • Primary key discovery and custom key configuration

§Prerequisites

Before using this source, you must:

  1. Enable CDC on the database:

    EXEC sys.sp_cdc_enable_db;
  2. Enable CDC on tables you want to monitor:

    EXEC sys.sp_cdc_enable_table
        @source_schema = N'dbo',
        @source_name = N'YourTable',
        @role_name = NULL;
  3. Ensure SQL Server Agent is running (required for CDC)

§Example

use drasi_source_mssql::{MsSqlSource, StartPosition};
use drasi_lib::Source;

let source = MsSqlSource::builder("mssql-source")
    .with_host("localhost")
    .with_database("production")
    .with_user("drasi_user")
    .with_password("secure_password")
    .with_tables(vec!["orders".to_string(), "customers".to_string()])
    .with_start_position(StartPosition::Beginning)  // Capture all retained changes
    .build()?;

source.start().await?;

Re-exports§

pub use decoder::CdcOperation;
pub use lsn::Lsn;

Modules§

config
Configuration for MS SQL CDC source
connection
MS SQL connection management using Tiberius
decoder
CDC operation decoder
descriptor
MS SQL source plugin descriptor and configuration DTOs.
error
Error types for MS SQL CDC source
keys
Primary key discovery and element ID generation
lsn
LSN (Log Sequence Number) handling for MS SQL CDC
stream
CDC polling stream implementation
types
Type conversion from MS SQL to Drasi ElementValue

Structs§

MsSqlConnection
MS SQL connection wrapper
MsSqlSource
MS SQL CDC Source
MsSqlSourceBuilder
Builder for MS SQL source
MsSqlSourceConfig
MS SQL CDC source configuration
PrimaryKeyCache
Cache of primary keys for tables
TableKeyConfig
Table key configuration for custom primary keys

Enums§

AuthMode
Authentication mode for MS SQL Server
ConnectionError
Connection-related error types
EncryptionMode
TLS/SSL encryption mode
LsnError
LSN-related error types
MsSqlError
Errors specific to MS SQL CDC operations
MsSqlErrorKind
Simplified error classification for control flow decisions
PrimaryKeyError
Primary key related error types
StartPosition
Starting position when no LSN is found in the state store

Functions§

validate_sql_identifier
Validate a SQL identifier to prevent SQL injection