TdsCdc.Capture (tds_cdc v0.1.0)

Copy Markdown

Handles querying SQL Server CDC tables and parsing the results.

This module is responsible for:

  • Checking if CDC is enabled on the database
  • Listing available capture instances
  • Fetching changes from CDC tables

Summary

Functions

Returns the SQL query to check if a specific capture instance exists.

Returns the SQL query to check if CDC is enabled on the current database.

Fetches all changes from a capture instance since the given LSN.

Gets the next LSN after the given one.

Gets the maximum LSN from the transaction log.

Gets the minimum LSN for a capture instance, which represents the earliest available change data.

Returns the SQL query to list all capture instances in the current database.

Functions

capture_instance_exists_query(capture_instance)

@spec capture_instance_exists_query(String.t()) :: String.t()

Returns the SQL query to check if a specific capture instance exists.

cdc_enabled_query()

@spec cdc_enabled_query() :: String.t()

Returns the SQL query to check if CDC is enabled on the current database.

fetch_changes(conn, capture_instance, from_lsn)

@spec fetch_changes(GenServer.server(), String.t(), binary()) ::
  {:ok, [TdsCdc.Change.t()]} | {:error, term()}

Fetches all changes from a capture instance since the given LSN.

This function performs three queries:

  1. Get the current max LSN
  2. Increment the from_lsn (since CDC functions are inclusive)
  3. Query the CDC change table function

Returns {:ok, changes} with a list of %Change{} structs, or {:error, reason}.

get_increment_lsn(conn, from_lsn)

@spec get_increment_lsn(GenServer.server(), binary()) ::
  {:ok, binary()} | {:error, term()}

Gets the next LSN after the given one.

get_max_lsn(conn)

@spec get_max_lsn(GenServer.server()) :: {:ok, binary()} | {:error, term()}

Gets the maximum LSN from the transaction log.

get_min_lsn(conn, capture_instance)

@spec get_min_lsn(GenServer.server(), String.t()) ::
  {:ok, binary()} | {:error, term()}

Gets the minimum LSN for a capture instance, which represents the earliest available change data.

list_capture_instances_query()

@spec list_capture_instances_query() :: String.t()

Returns the SQL query to list all capture instances in the current database.