### Run CDC Application with Configuration Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/fn.run_cdc_app.html This example demonstrates the basic usage of the `run_cdc_app` function. It loads configuration from environment variables and then calls `run_cdc_app` with the loaded configuration and no LSN file path. This is the simplest way to start a CDC application. ```rust use pg2any_lib::{app::run_cdc_app, load_config_from_env}; #[tokio::main] async fn main() -> Result<(), Box> { let config = load_config_from_env()?; run_cdc_app(config, None).await?; Ok(()) } ``` -------------------------------- ### LogicalReplicationStream::start Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationStream.html Starts the replication stream, initializing the replication slot (if it doesn't exist) and beginning to stream changes from PostgreSQL. It can optionally start from a specific LSN. ```APIDOC ## LogicalReplicationStream::start ### Description Start the replication stream. This initializes the replication slot (creating it if necessary) and begins streaming changes from PostgreSQL. ### Arguments * `start_lsn` - Optional LSN to start replication from. If `None`, starts from the current WAL position. Use this to resume replication from a known position. ### Returns Returns `Ok(())` if replication started successfully. ### Errors Returns an error if: * System identification fails * Replication slot creation fails (if it doesn’t exist) * Starting replication command fails ``` -------------------------------- ### Start Processing Timer Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/struct.ProcessingTimer.html Initializes and starts a new ProcessingTimer. Use this to begin timing a process. ```rust fn start(_event_type: &str, _destination_type: &str) -> Self ``` -------------------------------- ### Storage Usage Example Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/index.html Demonstrates how to create a storage instance from environment variables, write a transaction, and read a transaction using the StorageFactory and TransactionStorage trait. ```APIDOC ## Usage ```rust use pg2any_lib::storage::{StorageFactory, TransactionStorage}; // Create storage based on environment variable let storage = StorageFactory::from_env(); // Write transaction let statements = vec!["INSERT INTO users VALUES (1, 'Alice');".to_string()]; let file_path = storage.write_transaction(&path, &statements).await?; // Read transaction let statements = storage.read_transaction(&file_path, 0).await?; ``` ``` -------------------------------- ### Initialize CdcClient Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Prepares the CDC client for operation after creation. This method should be called before starting replication. ```rust pub async fn init(&mut self) -> Result<()> ``` -------------------------------- ### Start Replication Stream Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationStream.html Initializes the replication slot (creating it if necessary) and begins streaming changes from PostgreSQL. Use `start_lsn` to resume replication from a known position. ```rust stream.start(None).await?; ``` -------------------------------- ### Create New BufferWriter Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.BufferWriter.html Initializes a new BufferWriter. Use `new()` for a default initial capacity or `with_capacity()` to specify the starting size. ```rust pub fn new() -> BufferWriter ``` ```rust pub fn with_capacity(capacity: usize) -> BufferWriter ``` -------------------------------- ### Transactional Checkpoint Strategy Example Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/destination_factory/trait.DestinationHandler.html Illustrates how the `pre_commit_hook` ensures atomicity between data modifications and checkpoint updates within a single transaction. ```sql BEGIN; INSERT INTO users ...; UPDATE products ...; pre_commit_hook(); COMMIT; ``` -------------------------------- ### CdcClient::config Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Gets the current configuration of the CDC client. ```APIDOC ## CdcClient::config ### Description Get the current configuration. ### Method `pub fn config(&self) -> &Config` ``` -------------------------------- ### CdcClient::start_replication_from_lsn Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Starts CDC replication from a specific LSN. ```APIDOC ## CdcClient::start_replication_from_lsn ### Description Start CDC replication from a specific LSN. ### Method `pub async fn start_replication_from_lsn(&mut self, start_lsn: Option) -> Result<()>` ``` -------------------------------- ### Initialize ReplicationState Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ReplicationState.html Creates a new instance of ReplicationState. No specific setup is required beyond the struct's definition. ```rust pub fn new() -> ReplicationState ``` -------------------------------- ### ProcessingTimerTrait Implementations Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/struct.ProcessingTimer.html This section details the methods available for the ProcessingTimer struct through the ProcessingTimerTrait. These methods allow for starting and finishing timers to record metrics. ```APIDOC ## fn start(_event_type: &str, _destination_type: &str) -> Self ### Description Start a new processing timer ### Parameters - `_event_type` (str) - Description not available - `_destination_type` (str) - Description not available ### Returns - `Self` - A new instance of ProcessingTimer. ``` ```APIDOC ## fn finish(self, _collector: &dyn MetricsCollectorTrait) ### Description Finish timing and record the metric with the duration ### Parameters - `self` - The ProcessingTimer instance to finish. - `_collector` (dyn MetricsCollectorTrait) - The metrics collector to use for recording. ``` -------------------------------- ### Get Metrics in Prometheus Format Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Fetches and formats all collected metrics into the Prometheus text exposition format. ```rust pub fn get_metrics(&self) -> Result ``` -------------------------------- ### Get TypeId of CdcAppConfig Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcAppConfig.html Gets the TypeId of the CdcAppConfig instance. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### SqlServerDestination::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/sqlserver/struct.SqlServerDestination.html Creates a new instance of the SqlServerDestination. ```APIDOC ## SqlServerDestination::new ### Description Create a new SQL Server destination instance. ### Method `pub fn new() -> Self` ``` -------------------------------- ### SqlServerDestination::connect Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/sqlserver/struct.SqlServerDestination.html Initializes the destination connection using a connection string. ```APIDOC ## SqlServerDestination::connect ### Description Initialize the destination connection. ### Method `pub fn connect<'life0, 'life1, 'async_trait>( &'life0 mut self, connection_string: &'life1 str, ) -> Pin> + Send + 'async_trait>>` ### Parameters #### Path Parameters - **connection_string** (str) - Required - The connection string for the SQL Server instance. ``` -------------------------------- ### clone Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.CancellationToken.html Creates a clone of the CancellationToken which will get cancelled whenever the current token gets cancelled, and vice versa. ```APIDOC ## fn clone(&self) -> CancellationToken ### Description Creates a clone of the `CancellationToken` which will get cancelled whenever the current token gets cancelled, and vice versa. ``` -------------------------------- ### Create a new LogicalReplicationStream Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationStream.html Establishes a connection to PostgreSQL and prepares the stream for replication. It does not create the replication slot or start replication. The stream automatically creates a shared LSN feedback tracker accessible via the `shared_lsn_feedback` field, which the consumer should use to update flushed/applied LSN values after committing data. Connection string must include `replication=database` parameter. PostgreSQL version must be 14.0 or newer. ```rust use pg_walstream::{LogicalReplicationStream, ReplicationStreamConfig, RetryConfig, StreamingMode}; use std::time::Duration; let config = ReplicationStreamConfig::new( "my_slot".to_string(), "my_publication".to_string(), 2, StreamingMode::On, Duration::from_secs(10), Duration::from_secs(30), Duration::from_secs(60), RetryConfig::default(), ); let mut stream = LogicalReplicationStream::new( "postgresql://postgres:password@localhost:5432/mydb?replication=database", config, ).await?; // Access LSN feedback directly stream.shared_lsn_feedback.update_applied_lsn(12345); ``` -------------------------------- ### Get ColumnValue by Name Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.RowData.html Illustrates retrieving a column's value by its name using the `get` method. Note that this performs a linear scan. ```rust pub fn get(&self, name: &str) -> Option<&ColumnValue> ``` -------------------------------- ### ConfigBuilder::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/config/struct.ConfigBuilder.html Creates a new instance of the ConfigBuilder. ```APIDOC ## ConfigBuilder::new ### Description Creates a new config builder. ### Method `new()` ### Returns - `Self`: A new ConfigBuilder instance. ``` -------------------------------- ### CancellationToken::child_token Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.CancellationToken.html Creates a CancellationToken which will get cancelled whenever the current token gets cancelled. Cancelling a child token does not cancel the parent token. ```APIDOC ## pub fn child_token(&self) -> CancellationToken Creates a `CancellationToken` which will get cancelled whenever the current token gets cancelled. Unlike a cloned `CancellationToken`, cancelling a child token does not cancel the parent token. If the current token is already cancelled, the child token will get returned in cancelled state. ### Examples ``` use tokio::select; use tokio_util::sync::CancellationToken; #[tokio::main] async fn main() { let token = CancellationToken::new(); let child_token = token.child_token(); let join_handle = tokio::spawn(async move { // Wait for either cancellation or a very long time select! { _ = child_token.cancelled() => { // The token was cancelled 5 } _ = tokio::time::sleep(std::time::Duration::from_secs(9999)) => { 99 } } }); tokio::spawn(async move { tokio::time::sleep(std::time::Duration::from_millis(10)).await; token.cancel(); }); assert_eq!(5, join_handle.await.unwrap()); } ``` ``` -------------------------------- ### Run CdcApp with Graceful Shutdown Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcApp.html Starts the CDC replication process and manages graceful shutdown. It automatically loads the last LSN for resuming replication and initializes the metrics server if the feature is enabled. ```rust pub async fn run(&mut self) -> CdcResult<()> ``` -------------------------------- ### Get File Extension Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/trait.TransactionStorage.html Returns the file extension used by the specific storage implementation (e.g., 'sql' or 'sql.gz'). ```rust fn file_extension(&self) -> &str; ``` -------------------------------- ### Initialize LogicalReplicationStream Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationStream.html Configuration and initialization of a new LogicalReplicationStream. Ensure the connection string and replication parameters are correctly set. ```rust use pg_walstream::{LogicalReplicationStream, ReplicationStreamConfig, RetryConfig, StreamingMode}; use std::time::Duration; let config = ReplicationStreamConfig::new( "my_slot".to_string(), "my_publication".to_string(), 2, StreamingMode::On, Duration::from_secs(10), Duration::from_secs(30), Duration::from_secs(60), RetryConfig::default(), ); let mut stream = LogicalReplicationStream::new("connection_string", config).await?; // Start from the beginning stream.start(None).await?; // Or resume from a specific LSN // stream.start(Some(0x16B374D848)).await?; ``` -------------------------------- ### type_id(&self) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/enum.LogicalReplicationMessage.html Gets the `TypeId` of the LogicalReplicationMessage. ```APIDOC ## type_id(&self) ### Description Gets the `TypeId` of `self`. ### Signature `fn type_id(&self) -> TypeId` ``` -------------------------------- ### connect Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/destination_factory/trait.DestinationHandler.html Initializes the destination connection using a provided connection string. ```APIDOC ## connect ### Description Initialize the destination connection ### Method connect ### Parameters #### Path Parameters - **connection_string** (str) - Required - The connection string for the database. ``` -------------------------------- ### Create BEGIN Transaction Event Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.ChangeEvent.html Creates a BEGIN event to mark the start of a transaction in the replication stream. Requires transaction ID, final LSN, commit timestamp, and event LSN. ```rust pub fn begin( transaction_id: u32, final_lsn: Lsn, commit_timestamp: DateTime, lsn: Lsn, ) -> ChangeEvent ``` -------------------------------- ### Create and Use Transaction Storage Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/index.html Demonstrates creating a storage instance based on environment variables and performing write and read operations for transactions. Ensure necessary imports are present. ```rust use pg2any_lib::storage::{StorageFactory, TransactionStorage}; // Create storage based on environment variable let storage = StorageFactory::from_env(); // Write transaction let statements = vec!["INSERT INTO users VALUES (1, 'Alice');".to_string()]; let file_path = storage.write_transaction(&path, &statements).await?; // Read transaction let statements = storage.read_transaction(&file_path, 0).await?; ``` -------------------------------- ### CdcClient::get_stats Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Gets the replication statistics. ```APIDOC ## CdcClient::get_stats ### Description Get replication statistics. ### Method `pub fn get_stats(&self) -> ReplicationStats` ``` -------------------------------- ### Start Processing Timer Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/trait.ProcessingTimerTrait.html Initiates a new processing timer. This method requires the event type and destination type for context. ```rust fn start(event_type: &str, destination_type: &str) -> Self where Self: Sized; ``` -------------------------------- ### LogicalReplicationStream::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationStream.html Creates a new logical replication stream. This function establishes a connection to PostgreSQL and prepares the stream for replication but does not create the replication slot or start replication. It initializes a shared LSN feedback tracker for communication with the consumer. ```APIDOC ## LogicalReplicationStream::new ### Description Create a new logical replication stream. This establishes a connection to PostgreSQL and prepares the stream for replication. It does not create the replication slot or start replication - call `start()` for that. The stream automatically creates a shared LSN feedback tracker accessible via the `shared_lsn_feedback` field. The consumer should use this to update flushed/applied LSN values after committing data to the destination. This allows the stream to send accurate feedback to PostgreSQL, which is crucial for WAL retention management. ### Arguments * `connection_string` - PostgreSQL connection string. Must include `replication=database` parameter. Example: `"postgresql://user:pass@host:5432/dbname?replication=database"` * `config` - Replication stream configuration ### Returns A new `LogicalReplicationStream` instance with an initialized LSN feedback tracker. ### Errors Returns an error if: * Connection to PostgreSQL fails * Connection string is invalid * PostgreSQL version is too old (< 14.0) * Authentication fails ### Example ```rust use pg_walstream::{LogicalReplicationStream, ReplicationStreamConfig, RetryConfig, StreamingMode}; use std::time::Duration; let config = ReplicationStreamConfig::new( "my_slot".to_string(), "my_publication".to_string(), 2, StreamingMode::On, Duration::from_secs(10), Duration::from_secs(30), Duration::from_secs(60), RetryConfig::default(), ); let mut stream = LogicalReplicationStream::new( "postgresql://postgres:password@localhost:5432/mydb?replication=database", config, ).await?; // Access LSN feedback directly stream.shared_lsn_feedback.update_applied_lsn(12345); ``` ``` -------------------------------- ### Initialize Destination Connection Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/destination_factory/trait.DestinationHandler.html Implement this method to establish a connection to the database using the provided connection string. ```rust fn connect<'life0, 'life1, 'async_trait>( &'life0 mut self, connection_string: &'life1 str, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; ``` -------------------------------- ### Lsn::value Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.Lsn.html Gets the raw u64 value of the LSN. ```APIDOC ## Lsn::value ### Description Gets the raw u64 value of the LSN. ### Method `pub fn value(&self) -> u64` ### Returns The underlying 64-bit LSN value. ### Example ```rust use pg_walstream::Lsn; let lsn = Lsn::new(12345); assert_eq!(lsn.value(), 12345); ``` ``` -------------------------------- ### CdcClient::get_metrics Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Gets the metrics in Prometheus text format. ```APIDOC ## CdcClient::get_metrics ### Description Get metrics in Prometheus text format. ### Method `pub fn get_metrics(&self) -> Result` ``` -------------------------------- ### CdcClient::init_build_info Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Initializes build information in metrics. ```APIDOC ## CdcClient::init_build_info ### Description Initialize build information in metrics. ### Method `pub fn init_build_info(&self, version: &str)` ``` -------------------------------- ### CdcClient::init Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Initializes the CDC client. ```APIDOC ## CdcClient::init ### Description Initialize the CDC client. ### Method `pub async fn init(&mut self) -> Result<()>` ``` -------------------------------- ### CdcClient::metrics_collector Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Gets the metrics collector for accessing metrics. ```APIDOC ## CdcClient::metrics_collector ### Description Get metrics collector for accessing metrics. ### Method `pub fn metrics_collector(&self) -> Arc` ``` -------------------------------- ### Implement MetricsCollectorTrait: init_build_info() Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/struct.MetricsCollector.html Implements the `init_build_info` function for the MetricsCollectorTrait. This function is a no-op and does not initialize build information. ```rust fn init_build_info(&self, _version: &str) ``` -------------------------------- ### Create and use BufferReader Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.BufferReader.html Demonstrates creating a BufferReader from a byte slice and reading a single byte, then checking the remaining bytes. ```rust use pg_walstream::BufferReader; let data = vec![0x00, 0x01, 0x02, 0x03]; let mut reader = BufferReader::new(&data); let byte = reader.read_u8().unwrap(); assert_eq!(byte, 0x00); let remaining = reader.remaining(); assert_eq!(remaining, 3); ``` -------------------------------- ### impl Any for T Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.SharedLsnFeedback.html Provides a `type_id` method to get the `TypeId` of the implementing type. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### SQLiteDestination::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/sqlite/struct.SQLiteDestination.html Creates a new instance of the SQLite destination. ```APIDOC ## SQLiteDestination::new ### Description Create a new SQLite destination instance ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### UncompressedStorage::file_extension Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.UncompressedStorage.html Gets the file extension used by this storage implementation. ```APIDOC ## UncompressedStorage::file_extension ### Description Get the actual file extension used by this storage implementation. ### Method `pub fn file_extension(&self) -> &str` ``` -------------------------------- ### Initialize Build Information for Metrics Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Sets the version information for the build, which will be included in the metrics. ```rust pub fn init_build_info(&self, version: &str) ``` -------------------------------- ### CdcClient::cancellation_token Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Gets the cancellation token for external shutdown coordination. ```APIDOC ## CdcClient::cancellation_token ### Description Get the cancellation token for external shutdown coordination. ### Method `pub fn cancellation_token(&self) -> CancellationToken` ``` -------------------------------- ### Get the Number of Columns Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.TupleData.html Returns the total number of columns in the tuple data. ```rust pub fn column_count(&self) -> usize ``` -------------------------------- ### Initialize Build Info Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/trait.MetricsCollectorTrait.html Initializes build information, typically a version string. This method is thread-safe. ```rust fn init_build_info(&self, version: &str); ``` -------------------------------- ### Create New SqlStreamParser Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/sql_parser/struct.SqlStreamParser.html Instantiates a new SqlStreamParser. This is the entry point for using the streaming SQL parser. ```rust pub fn new() -> Self> ``` -------------------------------- ### CompressedStorage::file_extension Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.CompressedStorage.html Gets the actual file extension used by this storage implementation. ```APIDOC ## CompressedStorage::file_extension ### Description Get the actual file extension used by this storage implementation. ### Method `pub fn file_extension(&self) -> &str` ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.SharedLsnFeedback.html Provides the `type_id` method for getting the `TypeId` of the implementing type. ```APIDOC ## impl Any for T ### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### Get Replication Statistics Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Retrieves the current statistics related to the replication process. ```rust pub fn get_stats(&self) -> ReplicationStats ``` -------------------------------- ### read_transaction Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/trait.TransactionStorage.html Reads SQL commands from a transaction file, starting from a specified index. ```APIDOC ## read_transaction ### Description Reads SQL commands from a transaction file, starting from a specific index. ### Method `read_transaction` ### Parameters #### Path Parameters - `file_path` (Path) - Required - Path to the transaction file - `start_index` (usize) - Required - Zero-based index of first command to return ### Returns - `Vec` - SQL statements starting from start_index ``` -------------------------------- ### MySQLDestination::connect Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/mysql/struct.MySQLDestination.html Initializes the destination connection using a connection string. ```APIDOC ## MySQLDestination::connect ### Description Initialize the destination connection. ### Signature ```rust pub fn connect<'life0, 'life1, 'async_trait>( &'life0 mut self, connection_string: &'life1 str, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, ``` ``` -------------------------------- ### Get Event Type String Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.ChangeEvent.html Returns a string representation of the ChangeEvent's type. ```rust pub fn event_type_str(&self) -> &str ``` -------------------------------- ### Create BEGIN_PREPARE Event Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.ChangeEvent.html Creates a ChangeEvent for the beginning of a two-phase commit transaction (protocol v3+). Requires transaction ID, LSNs, timestamp, and GID. ```rust pub fn begin_prepare( transaction_id: u32, prepare_lsn: Lsn, end_lsn: Lsn, prepare_timestamp: DateTime, gid: impl Into>, lsn: Lsn, ) -> ChangeEvent ``` -------------------------------- ### Get Output Type for Same Trait Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.TupleData.html Defines the output type for the Same trait, which should always be Self. ```rust type Output = T> ``` -------------------------------- ### Get Column by Name Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Finds and returns a reference to a ColumnInfo struct by its name, if it exists. ```rust pub fn get_column_by_name(&self, name: &str) -> Option<&ColumnInfo> ``` -------------------------------- ### Create Config Builder Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/config/struct.Config.html Initializes a new builder for creating a Config instance. This is the entry point for constructing a configuration object. ```rust pub fn builder() -> ConfigBuilder ``` -------------------------------- ### Get Metrics Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/trait.MetricsCollectorTrait.html Retrieves collected metrics in Prometheus text format. This method is thread-safe. ```rust fn get_metrics(&self) -> CdcResult; ``` -------------------------------- ### Create CdcApp with CdcAppConfig Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcApp.html Initializes a new CdcApp instance using a CdcAppConfig. Handles potential errors during client creation or initialization. ```rust pub async fn new( config: CdcAppConfig, lsn_file_path: Option<&str>, ) -> CdcResult ``` -------------------------------- ### CdcApp::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcApp.html Creates a new CDC application instance with the provided configuration and optional LSN file path. ```APIDOC ## CdcApp::new ### Description Create a new CDC application instance. ### Arguments * `config` - The CDC application configuration to use. * `lsn_file_path` - Optional path to the LSN persistence file. ### Returns Returns a `CdcResult` with the initialized application instance. ### Errors Returns `CdcError` if the CDC client cannot be created or initialized. ``` -------------------------------- ### Get CdcClient Configuration Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Provides read-only access to the current configuration of the CDC client. ```rust pub fn config(&self) -> &Config ``` -------------------------------- ### UncompressedStorage::read_transaction Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.UncompressedStorage.html Reads SQL commands from a transaction file, starting from a specific index. ```APIDOC ## UncompressedStorage::read_transaction ### Description Read SQL commands from a transaction file, starting from a specific index. ### Method `pub fn read_transaction<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 Path, start_index: usize, ) -> Pin>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait` ``` -------------------------------- ### Create and Populate RowData Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.RowData.html Demonstrates creating a RowData instance with capacity and pushing column-value pairs. It also shows how to assert the length and retrieve values by column name. ```rust use pg_walstream::{RowData, ColumnValue}; use std::sync::Arc; let mut row = RowData::with_capacity(2); row.push(Arc::from("id"), ColumnValue::text("1")); row.push(Arc::from("name"), ColumnValue::text("Alice")); assert_eq!(row.len(), 2); assert_eq!(row.get("id").and_then(|v| v.as_str()), Some("1")); ``` -------------------------------- ### Create Storage from Environment Variable Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.StorageFactory.html Creates a storage implementation based on the PG2ANY_ENABLE_COMPRESSION environment variable. Returns CompressedStorage if the variable is set to true or 1, otherwise returns UncompressedStorage. ```rust pub fn from_env() -> Arc ``` -------------------------------- ### CompressedStorage::read_transaction Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.CompressedStorage.html Reads SQL commands from a transaction file, starting from a specific index. ```APIDOC ## CompressedStorage::read_transaction ### Description Read SQL commands from a transaction file, starting from a specific index. ### Method `pub fn read_transaction<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 Path, start_index: usize, ) -> Pin>> + Send + 'async_trait>>` ### Parameters #### Path Parameters - `file_path` (&'life1 Path) - The path to the transaction file. - `start_index` (usize) - The index from which to start reading. ``` -------------------------------- ### Generic Implementations for ColumnInfo Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ColumnInfo.html Demonstrates various blanket implementations available for ColumnInfo, including Any, Borrow, CloneToUninit, From, Instrument, Into, IntoEither, Same, ToOwned, TryFrom, TryInto, and VZip. These provide common functionalities like type identification, borrowing, cloning, conversion, and instrumentation. ```rust fn type_id(&self) -> TypeId ``` ```rust fn borrow(&self) -> &T ``` ```rust fn borrow_mut(&mut self) -> &mut T ``` ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` ```rust fn from(t: T) -> T ``` ```rust fn instrument(self, span: Span) -> Instrumented ``` ```rust fn in_current_span(self) -> Instrumented ``` ```rust fn into(self) -> U ``` ```rust fn into_either(self, into_left: bool) -> Either ``` ```rust fn into_either_with(self, into_left: F) -> Either where F: FnOnce(&Self) -> bool, ``` ```rust type Output = T ``` ```rust type Owned = T ``` ```rust fn to_owned(&self) -> T ``` ```rust fn clone_into(&self, target: &mut T) ``` ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` ```rust fn vzip(self) -> V ``` -------------------------------- ### Get Underlying Bytes Handle Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ColumnData.html Retrieves the underlying `Bytes` handle, which is a cheap ref-counted clone. ```rust pub fn raw_bytes(&self) -> Bytes ``` -------------------------------- ### Get Column by Index Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Retrieves a reference to a ColumnInfo struct based on its index in the columns vector. ```rust pub fn get_column_by_index(&self, index: usize) -> Option<&ColumnInfo> ``` -------------------------------- ### MySQLDestination::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/mysql/struct.MySQLDestination.html Creates a new instance of the MySQLDestination. ```APIDOC ## MySQLDestination::new ### Description Create a new MySQL destination instance. ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### Create New MySQLDestination Instance Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/mysql/struct.MySQLDestination.html Instantiates a new MySQL destination. This is the entry point for configuring and using the MySQL destination. ```rust pub fn new() -> Self ``` -------------------------------- ### Get Full Table Name Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Retrieves the fully qualified table name in the format 'namespace.relation_name'. ```rust pub fn full_name(&self) -> String ``` -------------------------------- ### CdcClient::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Creates a new CDC client with LSN tracking. It initializes the LSN tracker, loading from a persistence file if available, enabling graceful recovery. ```APIDOC ## CdcClient::new ### Description Creates a new CDC client and automatically initializes the LSN tracker for tracking committed LSN positions. The LSN tracker is loaded from the persistence file if it exists, allowing graceful recovery from previous runs. ### Method `pub async fn new(config: Config, lsn_file_path: Option<&str>) -> Result<(Self, Option` ### Parameters #### Arguments - `config` - The CDC configuration. - `lsn_file_path` - Optional path to the LSN persistence file. If None, uses the default from environment variables or "./pg2any_last_lsn.metadata". ### Returns Returns a tuple of (`CdcClient`, `Option`) where the `Lsn` is the last committed LSN loaded from the persistence file, or `None` if starting fresh. ``` -------------------------------- ### Get LSN Persistence File Path Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.LsnTracker.html Returns the file path configured for LSN persistence. ```rust pub fn file_path(&self) -> &str ``` -------------------------------- ### Get Current LSN Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.LsnTracker.html Retrieves the current last committed LSN (flush_lsn) as a `u64` value. ```rust pub fn get(&self) -> u64 ``` -------------------------------- ### BufferWriter Initialization Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.BufferWriter.html Methods for creating a new BufferWriter instance, either with default capacity or a specified capacity. ```APIDOC ## BufferWriter Initialization ### `new()` Creates a new buffer writer with default initial capacity. ### `with_capacity(capacity: usize)` Creates a new buffer writer with a specified initial capacity. ``` -------------------------------- ### TableMapping::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/config/struct.TableMapping.html Creates a new, default TableMapping instance. ```APIDOC ## `TableMapping::new()` ### Description Create a new table mapping. ### Method `new()` ### Returns `Self` (a new TableMapping instance) ``` -------------------------------- ### ColumnInfo::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ColumnInfo.html Constructor for creating a new ColumnInfo instance. ```APIDOC ### impl ColumnInfo #### pub fn new( flags: u8, name: String, type_id: u32, type_modifier: i32, ) -> ColumnInfo Creates a new ColumnInfo. ``` -------------------------------- ### Unwrap Err: Basic Usage Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/type.Result.html Use `unwrap_err` to get the `Err` value. Panics if the value is an `Ok`. ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Run PostgreSQL CDC Application Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/index.html Initializes logging, loads configuration from environment variables, and runs the CDC application. Ensure environment variables for configuration are set. ```rust use pg2any_lib::{load_config_from_env, run_cdc_app}; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize comprehensive logging init_logging(); tracing::info!("Starting PostgreSQL CDC Application"); // Load configuration from environment variables let config = load_config_from_env()?; // Run the CDC application with graceful shutdown handling run_cdc_app(config, None).await?; tracing::info!("CDC application stopped"); Ok(()) } ``` ```rust pub fn init_logging() { // Create a sophisticated logging setup let env_filter = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("pg2any=debug,tokio_postgres=info,sqlx=info")); let fmt_layer = fmt::layer() .with_target(true) .with_thread_ids(true) .with_level(true) .with_ansi(true) .compact(); tracing_subscriber::registry() .with(env_filter) .with(fmt_layer) .init(); tracing::info!("Logging initialized with level filtering"); } ``` -------------------------------- ### Unwrap Result: Basic Usage Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/type.Result.html Use `unwrap` to get the `Ok` value. Panics if the value is an `Err`. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Get Event Count Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.Transaction.html Returns the total number of change events currently stored within the transaction. ```rust pub fn event_count(&self) -> usize ``` -------------------------------- ### Load CompressionIndex from File Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.CompressionIndex.html Asynchronously loads a CompressionIndex from a specified file path. Returns a Result which is either the loaded index or an error. ```rust pub async fn load_from_file(path: &Path) -> Result ``` -------------------------------- ### Get RowData Length Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.RowData.html Shows how to retrieve the number of columns currently in the RowData using the `len` method. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Initialize MySQL Destination Connection Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/mysql/struct.MySQLDestination.html Establishes a connection to the MySQL destination using a provided connection string. This method is asynchronous and returns a Result indicating success or failure. ```rust pub fn connect<'life0, 'life1, 'async_trait>( &'life0 mut self, connection_string: &'life1 str, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, ``` -------------------------------- ### SqlStreamParser::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/sql_parser/struct.SqlStreamParser.html Creates a new instance of the SqlStreamParser. ```APIDOC ## SqlStreamParser::new ### Description Creates a new streaming parser. ### Method `new()` ### Returns - `Self`: A new instance of `SqlStreamParser`. ``` -------------------------------- ### Get Relation by OID Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ReplicationState.html Retrieves relation information by its Object ID (OID). Returns an Option<&RelationInfo>. ```rust pub fn get_relation(&self, relation_id: u32) -> Option<&RelationInfo> ``` -------------------------------- ### RelationInfo::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Constructor for creating a new RelationInfo instance. ```APIDOC ```rust pub fn new( relation_id: u32, namespace: String, relation_name: String, replica_identity: u8, columns: Vec, ) -> RelationInfo ``` ``` -------------------------------- ### Get Key Columns Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Returns a vector containing references to the columns that are part of the relation's key. ```rust pub fn get_key_columns(&self) -> Vec<&ColumnInfo> ``` -------------------------------- ### Create CdcApp with Config (Backwards Compatible) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcApp.html Creates a new CdcApp instance using only the CDC configuration, maintaining backwards compatibility. Errors during client creation or initialization are returned. ```rust pub async fn from_config( cdc_config: Config, lsn_file_path: Option<&str>, ) -> CdcResult ``` -------------------------------- ### AsRef<[u8]> Implementation Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.BufferWriter.html Provides a way to get a byte slice reference to the internal buffer data. ```APIDOC ## AsRef<[u8]> Implementation ### `as_bytes(&self) -> &[u8]` Returns a slice reference to the underlying byte buffer. ``` -------------------------------- ### compare Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.Lsn.html Compare self to `key` and return their ordering. ```APIDOC ## fn compare(&self, key: &K) -> Ordering ### Description Compare self to `key` and return their ordering. ### Method `fn` ### Parameters - **self**: `&self` - The object to compare. - **key**: `&K` - The key to compare against. ``` -------------------------------- ### Get Error Cause (Deprecated) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/enum.CdcError.html Returns the cause of the error. This method is deprecated and replaced by `Error::source`. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### Get CdcClient Metrics Collector Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Returns a shared reference to the MetricsCollector, allowing access to collected metrics. ```rust pub fn metrics_collector(&self) -> Arc ``` -------------------------------- ### Get Buffer as Bytes Slice Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.BufferWriter.html Provides a read-only slice view of the internal data without consuming the `BufferWriter`. ```rust pub fn as_bytes(&self) -> &[u8] ``` -------------------------------- ### UncompressedStorage::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.UncompressedStorage.html Creates a new instance of the UncompressedStorage handler. ```APIDOC ## UncompressedStorage::new ### Description Creates a new uncompressed storage handler. ### Method `pub fn new() -> Self` ``` -------------------------------- ### CompressionIndex Methods Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.CompressionIndex.html Provides methods for creating, saving, loading, and finding sync points within a CompressionIndex. ```APIDOC ## pub fn new() ### Description Create a new empty index. ### Method `new()` ### Returns - `Self`: A new empty `CompressionIndex` instance. ``` ```APIDOC ## pub fn find_sync_point_for_index(&self, target_index: usize) -> Option<&StatementOffset> ### Description Find the sync point to use for seeking to a given statement index. ### Method `find_sync_point_for_index(target_index: usize)` ### Parameters #### Path Parameters - `target_index` (usize) - Required - The statement index to find the sync point for. ### Returns - `Option<&StatementOffset>`: An optional reference to the `StatementOffset` if found, otherwise `None`. ``` ```APIDOC ## pub async fn save_to_file(&self, path: &Path) -> Result<()> ### Description Save index to a file. ### Method `save_to_file(path: &Path)` ### Parameters #### Path Parameters - `path` (&Path) - Required - The path to save the index file. ### Returns - `Result<()>`: Ok(()) if successful, otherwise an error. ``` ```APIDOC ## pub async fn load_from_file(path: &Path) -> Result ### Description Load index from a file. ### Method `load_from_file(path: &Path)` ### Parameters #### Path Parameters - `path` (&Path) - Required - The path to load the index file from. ### Returns - `Result`: The loaded `CompressionIndex` if successful, otherwise an error. ``` -------------------------------- ### ConfigBuilder::build Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/config/struct.ConfigBuilder.html Builds the final configuration object. ```APIDOC ## ConfigBuilder::build ### Description Build the configuration. ### Method `build()` ### Returns - `Result`: A Result containing the constructed `Config` object on success, or an error if the configuration is invalid. ``` -------------------------------- ### Get Error Description (Deprecated) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/enum.CdcError.html Provides a description of the error. This method is deprecated and `Display` or `to_string()` should be used instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### ProcessingTimerTrait Definition Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/trait.ProcessingTimerTrait.html Defines the interface for processing timers. Use `start` to begin timing and `finish` to record the duration. ```rust pub trait ProcessingTimerTrait { // Required methods fn start(event_type: &str, destination_type: &str) -> Self where Self: Sized; fn finish(self, collector: &dyn MetricsCollectorTrait); } ``` -------------------------------- ### Constant BEGIN_PREPARE Definition Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/message_types/constant.BEGIN_PREPARE.html Defines the BEGIN_PREPARE constant as a u8 byte. This is used to signify the start of a prepare message. ```rust pub const BEGIN_PREPARE: u8 = b'b'; // 98u8 ``` -------------------------------- ### Create New ReplicationStreamConfig Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.ReplicationStreamConfig.html Initializes a new ReplicationStreamConfig with essential parameters. Ensure that the protocol version and streaming mode are compatible. ```rust use pg_walstream::{ReplicationStreamConfig, RetryConfig, StreamingMode}; use std::time::Duration; let config = ReplicationStreamConfig::new( "my_slot".to_string(), "my_publication".to_string(), 2, StreamingMode::On, Duration::from_secs(10), Duration::from_secs(30), Duration::from_secs(60), RetryConfig::default(), ); ``` -------------------------------- ### CompressedStorage::new Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.CompressedStorage.html Creates a new instance of the CompressedStorage handler. ```APIDOC ## CompressedStorage::new ### Description Create a new compressed storage handler. ### Method `pub fn new() -> Self` ``` -------------------------------- ### Get Column Data by Index Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.TupleData.html Retrieves a reference to the column data at the specified index, returning None if the index is out of bounds. ```rust pub fn get_column(&self, index: usize) -> Option<&ColumnData> ``` -------------------------------- ### Create and use SharedLsnFeedback Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.SharedLsnFeedback.html Demonstrates the basic usage of SharedLsnFeedback for tracking LSN positions. It shows how a consumer updates flushed and applied LSNs, and how a producer can read these values for feedback to PostgreSQL. ```rust use pg_walstream::lsn::SharedLsnFeedback; use std::sync::Arc; let feedback = SharedLsnFeedback::new_shared(); // Consumer updates LSN after flushing data feedback.update_flushed_lsn(1000); // Consumer updates LSN after committing transaction feedback.update_applied_lsn(1000); // Producer reads LSN values for feedback to PostgreSQL let (flushed, applied) = feedback.get_feedback_lsn(); ``` -------------------------------- ### MetricsCollectorTrait::init_build_info Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/monitoring/metrics_abstraction/trait.MetricsCollectorTrait.html Initializes the build information. This method is thread-safe and handles any necessary locking internally. ```APIDOC ## fn init_build_info(&self, version: &str) ### Description Initialize build information. ### Parameters - **version** (*&str*): The build version string. ``` -------------------------------- ### Get Current Metadata Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.LsnTracker.html Returns a copy of the current metadata tracked by the LSN tracker. This includes the LSN and consumer state. ```rust pub fn get_metadata(&self) -> CdcMetadata ``` -------------------------------- ### Get CdcClient Cancellation Token Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Retrieves the CancellationToken associated with the client. This token can be used for external coordination of shutdown processes. ```rust pub fn cancellation_token(&self) -> CancellationToken ``` -------------------------------- ### New RelationInfo Instance Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.RelationInfo.html Constructor for creating a new RelationInfo instance. ```rust pub fn new( relation_id: u32, namespace: String, relation_name: String, replica_identity: u8, columns: Vec, ) -> RelationInfo ``` -------------------------------- ### Define BEGIN Constant Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/message_types/constant.BEGIN.html Defines the BEGIN constant as a u8 byte representing 'B'. This is used to signify the start of a message. ```rust pub const BEGIN: u8 = b'B'; // 66u8 ``` -------------------------------- ### Create LogicalReplicationParser with Protocol Version Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/struct.LogicalReplicationParser.html Instantiate a new LogicalReplicationParser by specifying the desired PostgreSQL protocol version. This is essential for correct message interpretation. ```rust pub fn with_protocol_version(protocol_version: u32) -> LogicalReplicationParser ``` -------------------------------- ### And: Combining Results (Err Cases) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/type.Result.html The `and` method returns the first `Result` if it is `Err`. This example shows different `Err` scenarios. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("late error")); let x: Result = Err("early error"); let y: Result<&str, &str> = Ok("foo"); assert_eq!(x.and(y), Err("early error")); let x: Result = Err("not a 2"); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("not a 2")); ``` -------------------------------- ### And: Combining Results (Ok Case) Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/error/type.Result.html The `and` method returns the second `Result` if the first is `Ok`. This example shows the `Ok` case. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Ok("different result type"); assert_eq!(x.and(y), Ok("different result type")); ``` -------------------------------- ### SQLiteDestination::connect Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/destinations/sqlite/struct.SQLiteDestination.html Initializes the SQLite destination connection using a connection string. ```APIDOC ## SQLiteDestination::connect ### Description Initialize the destination connection ### Signature ```rust pub fn connect<'life0, 'life1, 'async_trait>( &'life0 mut self, connection_string: &'life1 str, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, ``` ``` -------------------------------- ### Get Key Columns Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/types/struct.ChangeEvent.html Retrieves the key columns from an UPDATE or DELETE ChangeEvent. Returns None if the event does not contain key columns. ```rust pub fn get_key_columns(&self) -> Option<&Vec>> ``` -------------------------------- ### Create a new SharedLsnFeedback instance Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/lsn_tracker/struct.SharedLsnFeedback.html Initializes a new SharedLsnFeedback tracker with both flushed and applied LSNs set to 0. Use `new_shared()` for thread-safe sharing. ```rust use pg_walstream::lsn::SharedLsnFeedback; let feedback = SharedLsnFeedback::new(); assert_eq!(feedback.get_flushed_lsn(), 0); assert_eq!(feedback.get_applied_lsn(), 0); ``` -------------------------------- ### Get File Extension for Uncompressed Storage Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/storage/struct.UncompressedStorage.html Returns the file extension used by this UncompressedStorage implementation. For uncompressed storage, this is typically '.sql'. ```rust fn file_extension(&self) -> &str ``` -------------------------------- ### Create New CdcClient Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/client/struct.CdcClient.html Initializes a new CDC client with LSN tracking capabilities. It loads the LSN tracker from a persistence file if available, enabling graceful recovery. ```rust pub async fn new( config: Config, lsn_file_path: Option<&str>, ) -> Result<(Self, Option)> ``` -------------------------------- ### CdcApp::from_config Source: https://docs.rs/pg2any_lib/latest/pg2any_lib/app/struct.CdcApp.html Creates a new CDC application instance using only the CDC configuration, providing backwards compatibility. ```APIDOC ## CdcApp::from_config ### Description Create a new CDC application instance with just the CDC config (backwards compatible). ### Arguments * `cdc_config` - The CDC configuration to use. * `lsn_file_path` - Optional path to the LSN persistence file. ### Returns Returns a `CdcResult` with the initialized application instance. ### Errors Returns `CdcError` if the CDC client cannot be created or initialized. ```