motherduck_supasync/lib.rs
1//! # MotherDuck SupaSync
2//!
3//! A robust Rust library for syncing Supabase PostgreSQL data to MotherDuck for analytics.
4//!
5//! ## Features
6//!
7//! - **Incremental sync**: Only sync records that haven't been synced yet
8//! - **Full sync**: Re-sync all records
9//! - **Retry logic**: Automatic retries with exponential backoff
10//! - **Schema management**: Automatic table creation and migrations
11//! - **Batch processing**: Efficient batch inserts for large datasets
12//! - **Progress tracking**: Real-time progress updates via callbacks
13//! - **Metrics**: Built-in metrics for observability
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! use motherduck_supasync::{SyncClient, SyncConfig, SyncMode};
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! let config = SyncConfig::builder()
23//! .postgres_url("postgres://user:pass@host:5432/db")
24//! .motherduck_token("your_token")
25//! .motherduck_database("analytics")
26//! .build()?;
27//!
28//! let client = SyncClient::new(config).await?;
29//! let result = client.sync(SyncMode::Incremental).await?;
30//!
31//! println!("Synced {} records", result.total_records());
32//! Ok(())
33//! }
34//! ```
35//!
36//! ## Custom Tables
37//!
38//! You can define custom table mappings:
39//!
40//! ```rust,no_run
41//! use motherduck_supasync::{SyncClient, SyncConfig, TableMapping};
42//!
43//! let mapping = TableMapping::builder()
44//! .source_table("my_source_table")
45//! .target_table("my_target_table")
46//! .primary_key(["id"])
47//! .sync_flag_column("synced")
48//! .build();
49//! ```
50
51#![cfg_attr(docsrs, feature(doc_cfg))]
52#![warn(missing_docs)]
53#![warn(rustdoc::missing_crate_level_docs)]
54#![deny(unsafe_code)]
55
56pub mod config;
57pub mod error;
58pub mod metrics;
59pub mod motherduck;
60pub mod postgres;
61pub mod schema;
62pub mod sync;
63
64// Re-exports for convenience
65pub use config::{SyncConfig, SyncConfigBuilder, TableMapping, TableMappingBuilder};
66pub use error::{Error, Result};
67pub use motherduck::MotherDuckClient;
68pub use schema::{Column, ColumnType, Schema};
69pub use sync::{SyncClient, SyncMode, SyncProgress, SyncResult};
70
71/// Library version
72pub const VERSION: &str = env!("CARGO_PKG_VERSION");