ferrule-sql
The embeddable, synchronous, bounded-memory SQL core behind the
ferruleCLI.
ferrule-sql is the database layer of ferrule carved out as a standalone,
embeddable crate. It owns the unified neutral Value/Row types, the
DatabaseUrl parser, the Connection trait and its per-backend drivers, the
connect dispatcher (direct, HTTP-proxy, and SSH-tunnel transports), the
transaction helpers, and the cross-backend copy / bulk-load write path.
It carries no rendering (tabled) and no credential-resolution
(ferrule-config) dependency, so a host application can embed it directly and
supply already-resolved connection details.
Why these properties
- Synchronous public API. No
async fn/Futurecrosses the crate boundary, so a host with no runtime of its own can call straight through. The async network drivers are still used — eachConnectionowns a private current-threadtokioruntime and blocks on it — but that runtime is an implementation detail. SQLite and Oracle are natively synchronous and call through directly. - Bounded memory.
Connection::query_cursorstreams from a native database cursor one back-pressured batch at a time, andwrite_rowsflushes an arbitrarily large row iterator in fixed-size batches — both stayO(batch)regardless of total row count. The eagerConnection::queryis capped by per-cell / per-row / per-resultSizeGuardsso a pathological result fails fast instead of OOMing. - Caller-resolved credentials.
connecttakes the password as asecrecy::SecretStringonConnectOptions; the crate performs no credential resolution and depends on no keyring / prompt library. The secret is redacted inDebugand zeroized on drop.
Backends (feature flags)
The default feature set is empty — enable the backends you need.
| Feature | Driver | C-free |
|---|---|---|
postgres |
tokio-postgres + rustls/ring |
yes |
mysql |
mysql_async (rustls/ring) |
yes¹ |
mssql |
tiberius |
— |
sqlite |
rusqlite (bundled) |
yes² |
oracle |
oracle (ODPI-C, opt-in) |
no |
ssh |
russh (ring) tunnel transport |
yes |
¹ Pulls a vendored-static zstd-sys (a hard, non-feature-gated dependency of
mysql_common); no system-library linkage. ² bundled statically links a
vendored SQLite. "C-free" here means: no cmake, no system-library linkage —
self-contained vendored-static cc builds (ring, zstd, bundled SQLite)
are accepted.
Example
connect → streaming read → batched write, the same three steps documented on
the crate root and in the runnable
examples/embed.rs
(cargo run -p ferrule-sql --example embed --features sqlite):
use ;
use SecretString;
#
Relationship to ferrule
ferrule-sql is the lower half of the ferrule
workspace. The ferrule CLI layers rendering, credential resolution, a
connection registry, and the command tree on top. Embedders who only need to
talk to databases — without the CLI's output or config machinery — depend on
ferrule-sql alone.
License
Licensed under either of MIT or Apache-2.0 (SPDX: MIT OR Apache-2.0) at your
option.