Crate motherduck_supasync

Crate motherduck_supasync 

Source
Expand description

§MotherDuck SupaSync

A robust Rust library for syncing Supabase PostgreSQL data to MotherDuck for analytics.

§Features

  • Incremental sync: Only sync records that haven’t been synced yet
  • Full sync: Re-sync all records
  • Retry logic: Automatic retries with exponential backoff
  • Schema management: Automatic table creation and migrations
  • Batch processing: Efficient batch inserts for large datasets
  • Progress tracking: Real-time progress updates via callbacks
  • Metrics: Built-in metrics for observability

§Quick Start

use motherduck_supasync::{SyncClient, SyncConfig, SyncMode};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = SyncConfig::builder()
        .postgres_url("postgres://user:pass@host:5432/db")
        .motherduck_token("your_token")
        .motherduck_database("analytics")
        .build()?;

    let client = SyncClient::new(config).await?;
    let result = client.sync(SyncMode::Incremental).await?;

    println!("Synced {} records", result.total_records());
    Ok(())
}

§Custom Tables

You can define custom table mappings:

use motherduck_supasync::{SyncClient, SyncConfig, TableMapping};

let mapping = TableMapping::builder()
    .source_table("my_source_table")
    .target_table("my_target_table")
    .primary_key(["id"])
    .sync_flag_column("synced")
    .build();

Re-exports§

pub use config::SyncConfig;
pub use config::SyncConfigBuilder;
pub use config::TableMapping;
pub use config::TableMappingBuilder;
pub use error::Error;
pub use error::Result;
pub use motherduck::MotherDuckClient;
pub use schema::Column;
pub use schema::ColumnType;
pub use schema::Schema;
pub use sync::SyncClient;
pub use sync::SyncMode;
pub use sync::SyncProgress;
pub use sync::SyncResult;

Modules§

config
Configuration types and builders for motherduck-supasync.
error
Error types for motherduck-supasync.
metrics
Metrics and observability for motherduck-supasync.
motherduck
MotherDuck client and operations for motherduck-supasync.
postgres
PostgreSQL client and operations for motherduck-supasync.
schema
Schema types and DDL generation for motherduck-supasync.
sync
Core sync logic for motherduck-supasync.

Constants§

VERSION
Library version