Expand description
§mssql-tiberius-bridge
A tiberius-compatible API bridge over Microsoft’s mssql-tds crate.
Migrate from tiberius with minimal code changes.
This crate wraps mssql-tds (Microsoft’s official Rust TDS protocol implementation)
and provides the familiar tiberius-style API: named column access via row.get::<T, _>("col"),
into_first_result(), positional @P1, @P2 parameter binding, and a fluent Config builder.
§Quick Start
use mssql_tiberius_bridge::{Config, AuthMethod, Client};
#[tokio::main]
async fn main() -> mssql_tiberius_bridge::Result<()> {
let mut cfg = Config::new();
cfg.host("localhost")
.port(1433)
.database("master")
.authentication(AuthMethod::sql_server("sa", "password"))
.trust_cert();
let mut client = Client::connect(&cfg).await?;
// Simple query
let rows = client
.simple_query("SELECT name FROM sys.databases")
.await?
.into_first_result();
for row in &rows {
let name: &str = row.get("name").unwrap();
println!("{name}");
}
// Parameterized query
let rows = client
.query("SELECT @P1 AS greeting, @P2 AS number", &[&"hello", &42i32])
.await?
.into_first_result();
let greeting: &str = rows[0].get("greeting").unwrap();
let number: i32 = rows[0].get("number").unwrap();
println!("{greeting} {number}");
Ok(())
}§Feature Flags
| Flag | Default | Description |
|---|---|---|
json | off | Enables serde_json::Value support for FromSql and ToSql |
time | off | Enables time crate support for FromSql and ToSql |
jiff | off | Enables jiff crate support for FromSql and ToSql |
serde | off | Enables serde::Deserialize for Row (see [serde_de]) |
arrow | off | Enables BulkInsert::send_arrow for Apache Arrow RecordBatch input (see [bulk_arrow]) |
§Modules
client—Clientwrapper withsimple_query,query,executeconfig—Configbuilder,AuthMethod,EncryptionLevelrow—Rowwith named/indexed access,FromSqltraitquery—QueryResult,ToSqltrait,ExecuteResult- [
column] —Columnmetadata,ColumnTypeenum pool— Connection pooling viadeadpoolerror—ErrorandResulttypes
§Migration from tiberius
See the README for a full migration table. Key differences:
- TCP transport is handled internally — no
TcpStreamboilerplate row.get::<&str, _>("col")works (strings are pre-decoded from UTF-16)- Connection pooling via
TdsManager+deadpool
Re-exports§
pub use bulk::BulkInsert;pub use client::Client;pub use column::Collation;pub use column::Column;pub use column::ColumnType;pub use column::MultiPartName;pub use config::AuthMethod;pub use config::Config;pub use config::EncryptionLevel;pub use config::Transport;pub use error::Error;pub use error::Result;pub use pool::Pool;pub use pool::PooledConnection;pub use pool::TdsManager;pub use query::DebugParams;pub use query::ExecuteResult;pub use query::QueryResult;pub use query::ToSql;pub use row::ColumnIndex;pub use row::FromSql;pub use row::Row;
Modules§
- bulk
- Bulk insert (BCP) — high-throughput row loading via the TDS BulkLoadBCP token.
- client
- SQL Server client with tiberius-compatible query methods.
- column
- Column type enumeration mirroring tiberius’ ColumnType.
- config
- Connection configuration builder mirroring tiberius’
ConfigAPI. - error
- Error types for mssql-tiberius-bridge.
- pool
- Connection pooling via
deadpool, mirroring the tiberius + deadpool pattern. - query
- Query result types and the
ToSqltrait for parameter binding. - row
- Row type with named and indexed column access, mirroring tiberius’
RowAPI.
Structs§
- Column
Mapping - Defines a mapping between a source column and a destination column.
- Decimal
Parts - Decimal/Numeric value representation from mssql-tds.
Returned inside
ColumnValues::DecimalandColumnValues::Numeric. TDS representation of Decimal and Numeric types. - TdsClient
- The underlying mssql-tds client type, exposed for advanced operations
via
Client::inner_mut(). Active TDS connection to a SQL Server instance.
Enums§
- Column
Mapping Source - Specifies how to map source columns to destination columns.
- Column
Values - Raw column values from mssql-tds, exposed for low-level access
via
Row::raw_value(). Decoded column value from a TDS result row.
Traits§
- Bulk
Load Row - Zero-copy bulk copy trait for direct serialization to TDS packets.