pg2any_lib/lib.rs
1//! # PostgreSQL CDC Library
2//!
3//! A comprehensive Change Data Capture (CDC) library for PostgreSQL using logical replication.
4//! This library allows you to stream database changes in real-time from PostgreSQL to other databases
5//! such as SQL Server, MySQL, and more.
6//!
7//! ## Features
8//!
9//! - PostgreSQL logical replication support
10//! - Real-time change streaming (INSERT, UPDATE, DELETE, TRUNCATE)
11//! - Multiple destination database support (SQL Server, MySQL)
12//! - Async/await support with Tokio
13//! - Comprehensive error handling
14//! - Thread-safe operations
15//! - Built-in backpressure handling
16//!
17//! ## Quick Start
18//!
19//! ```rust,no_run
20//! use pg2any_lib::{CdcClient, Config, DestinationType};
21//!
22//! #[tokio::main]
23//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//! let config = Config::builder()
25//! .source_connection_string("postgresql://user:password@localhost/source_db")
26//! .destination_type(DestinationType::MySQL)
27//! .destination_connection_string("mysql://user:password@localhost/target_db")
28//! .replication_slot_name("my_cdc_slot")
29//! .publication_name("my_publication")
30//! .build()?;
31//!
32//! let mut client = CdcClient::new(config).await?;
33//! client.start_replication_from_lsn(None).await?;
34//!
35//! Ok(())
36//! }
37//! ```
38
39// Core modules
40pub mod app;
41pub mod config;
42pub mod env;
43pub mod error;
44
45// Destination handlers
46pub mod types;
47
48// Low-level PostgreSQL replication using libpq-sys
49pub mod buffer;
50pub mod pg_replication;
51
52// Unified replication protocol implementation
53pub mod logical_stream;
54pub mod replication_protocol;
55
56// High-level client interface
57pub mod client;
58pub mod connection;
59
60// Public API exports
61pub use app::{run_cdc_app, CdcApp};
62pub use client::CdcClient;
63pub use config::{Config, ConfigBuilder};
64pub use env::load_config_from_env;
65pub use error::CdcError;
66
67/// Result type for CDC operations
68pub type CdcResult<T> = Result<T, CdcError>;
69
70pub mod destinations;
71
72// Re-export implementations
73#[cfg(feature = "mysql")]
74pub use crate::destinations::MySQLDestination;
75
76#[cfg(feature = "sqlserver")]
77pub use crate::destinations::SqlServerDestination;
78
79pub use crate::destinations::{DestinationFactory, DestinationHandler};
80pub use crate::replication_protocol::{
81 ColumnData, ColumnInfo, LogicalReplicationMessage, LogicalReplicationParser, RelationInfo,
82 ReplicationState, TupleData,
83};
84pub use crate::types::DestinationType;