Skip to main content

Crate mssql_tiberius_bridge

Crate mssql_tiberius_bridge 

Source
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

FlagDefaultDescription
jsonoffEnables serde_json::Value support for FromSql and ToSql
timeoffEnables time crate support for FromSql and ToSql
jiffoffEnables jiff crate support for FromSql and ToSql
serdeoffEnables serde::Deserialize for Row (see [serde_de])
arrowoffEnables BulkInsert::send_arrow for Apache Arrow RecordBatch input (see [bulk_arrow])

§Modules

§Migration from tiberius

See the README for a full migration table. Key differences:

  • TCP transport is handled internally — no TcpStream boilerplate
  • 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’ Config API.
error
Error types for mssql-tiberius-bridge.
pool
Connection pooling via deadpool, mirroring the tiberius + deadpool pattern.
query
Query result types and the ToSql trait for parameter binding.
row
Row type with named and indexed column access, mirroring tiberius’ Row API.

Structs§

ColumnMapping
Defines a mapping between a source column and a destination column.
DecimalParts
Decimal/Numeric value representation from mssql-tds. Returned inside ColumnValues::Decimal and ColumnValues::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§

ColumnMappingSource
Specifies how to map source columns to destination columns.
ColumnValues
Raw column values from mssql-tds, exposed for low-level access via Row::raw_value(). Decoded column value from a TDS result row.

Traits§

BulkLoadRow
Zero-copy bulk copy trait for direct serialization to TDS packets.