mssql-client
High-level async SQL Server client with type-state connection management.
Overview
This is the primary public API surface for the rust-mssql-driver project. It provides a type-safe, ergonomic interface for working with SQL Server databases using modern async Rust patterns.
Features
- Type-state pattern: Compile-time enforcement of connection states
- Async/await: Built on Tokio for efficient async I/O
- Parameterized queries: Server-side plan reuse via
sp_executesql(a client-side statement cache is planned) - Transactions: Full transaction support with savepoints
- Azure support: Automatic routing and failover handling
- Lazy row decoding: Rows decode on demand from the buffered response (true streaming from the socket is planned)
- Bulk insert: Bulk data loading via BCP
- Table-valued parameters: Pass collections to stored procedures
Type-State Connection Management
The client uses a compile-time type-state pattern that ensures invalid operations are caught at compile time:
Disconnected -> Ready (via connect())
Ready -> InTransaction (via begin_transaction())
InTransaction -> Ready (via commit() or rollback())
Usage
use ;
async
Transactions with Savepoints
use ;
async
Large Result Sets
use ;
async
Bulk Insert
use ;
async
Feature Flags
| Flag | Default | Description |
|---|---|---|
chrono |
Yes | Date/time type support via chrono |
uuid |
Yes | UUID type support |
decimal |
Yes | Decimal type support via rust_decimal |
encoding |
Yes | Collation-aware VARCHAR decoding |
json |
No | JSON type support via serde_json |
otel |
No | OpenTelemetry instrumentation |
zeroize |
No | Secure credential wiping |
always-encrypted |
No | Client-side encryption with key providers |
Modules
| Module | Description |
|---|---|
client |
Main Client type and connection management |
config |
Connection configuration and parsing |
query |
Query building and execution |
row |
Row and column access |
stream |
Result streaming types |
transaction |
Transaction and savepoint handling |
bulk |
Bulk insert operations |
tvp |
Table-valued parameters |
from_row |
Row-to-struct mapping trait |
to_params |
Struct-to-parameters trait |
instrumentation |
OpenTelemetry integration |
Examples
See the examples/ directory for complete examples:
basic.rs- Simple queries and parameter bindingtransactions.rs- Transaction handling with savepointsbulk_insert.rs- Bulk loadingderive_macros.rs- Using#[derive(FromRow)]and#[derive(ToParams)]streaming.rs- Iterating large result sets (lazy row decoding)
Development
Built with heavy AI assistance, with a human maintainer reviewing and accountable for every change. The protocol layer has unit and property tests, and an integration suite runs against a real SQL Server in CI; known gaps are tracked in LIMITATIONS.md.
License
MIT OR Apache-2.0