hinge 0.1.0

SQL-native ELT engine — dependency graph resolved automatically from FROM/JOIN clauses, parallel execution, single binary
Documentation
use sqlx::PgPool;
use sqlx::postgres::PgPoolOptions;
use std::time::Duration;

/// Executes SQL assets against a PostgreSQL database.
///
/// Each asset runs inside its own transaction with an advisory lock on
/// `(schema, name)`, preventing concurrent rebuilds of the same asset.
///
/// # Connection string
///
/// ```text
/// postgresql://user:password@host:5432/database
/// postgres://user:password@host/database
/// ```
///
/// # Example
///
/// ```rust,ignore
/// # use hinge::PostgresExecutor;
/// # async fn example() -> Result<(), sqlx::Error> {
/// let executor = PostgresExecutor::new("postgresql://user:pass@localhost/mydb").await?;
/// # Ok(())
/// # }
/// ```
pub struct PostgresExecutor {
    pool: PgPool,
}

impl PostgresExecutor {
    /// Connect to PostgreSQL and create a connection pool (up to 50 connections).
    pub async fn new(url: &str) -> Result<Self, sqlx::Error> {
        let pool = PgPoolOptions::new()
            .max_connections(50)
            .acquire_timeout(Duration::from_secs(60))
            .connect(url)
            .await?;
        Ok(Self { pool })
    }

    pub(super) fn pool(&self) -> &PgPool {
        &self.pool
    }
}