Skip to main content

Crate hinge

Crate hinge 

Source
Expand description

SQL-native ELT engine — single binary, no runtime required.

Hone walks a directory of .sql files, builds a dependency graph by parsing FROM / JOIN clauses, and executes every asset in the correct order — running independent assets in parallel within each wave.

§Quick start

use hinge::{BuildGraph, RunAll, PostgresExecutor};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let graph    = BuildGraph::from_dir("models")?;
    let executor = PostgresExecutor::new("postgresql://user:pass@localhost/mydb").await?;
    RunAll::new(graph, executor).execute().await?;
    Ok(())
}

§File layout

models/
  raw/
    events.sql          →  raw.events
  staging/
    orders.sql          →  staging.orders   (SELECT … FROM raw.events)
  mart/
    revenue.sql         →  mart.revenue     (SELECT … FROM staging.orders)

Dependencies are resolved automatically — no ref() calls, no manifest files.

§Asset kinds

Declare the output type with a header comment at the top of the file. Defaults to view when absent.

-- @kind: table
-- @kind: view
-- @kind: materialized_view
SELECT …

§Run modes

TypeBehaviour
RunAllFull graph in dependency order
RunUpstreamAll ancestors of a node, then the node itself
RunDownstreamThe node, then all its descendants
RunBidirectionalBoth directions from a node

Every run type exposes .plan() for a dry-run preview that resolves the execution order without connecting to the database.

Structs§

Asset
A SQL asset: a named SQL fragment that produces a relation in a database.
AssetReference
A schema.name pair that uniquely identifies an asset in the graph.
AssetSource
The SQL body of an asset — the SELECT statement that defines it.
BuildGraph
Scans a directory of .sql files and builds a Graph with automatic dependency resolution.
ClickHouseExecutor
Executes SQL assets against a ClickHouse server.
DuckDbExecutor
Executes SQL assets against a DuckDB database.
Engine
Graph
A directed acyclic graph (DAG) of SQL assets.
PostgresExecutor
Executes SQL assets against a PostgreSQL database.
RunAll
Executes all assets in the graph in topological order.
RunBidirectional
Executes the full upstream subgraph, the target asset, then the full downstream subgraph.
RunDownstream
Executes a target asset, then all assets that depend on it.
RunUpstream
Executes all ancestors of a target asset, then the asset itself.
SnowflakeExecutor
Executes SQL assets against a Snowflake data warehouse.

Enums§

AssetError
Errors returned when constructing asset value objects.
AssetKind
The type of database object an asset produces.
BuildGraphError
Errors that can occur while scanning a models directory and building the graph.
DuckDbConnectionError
ExecutorError
Error returned when an asset fails to execute against the database.
GraphError
Errors returned when building a Graph.
SnowflakeConnectionError

Traits§

Executor
Executes a single SQL asset against a database.