mssql_tiberius_bridge/lib.rs
1//! # mssql-tiberius-bridge
2//!
3//! A tiberius-compatible API bridge over Microsoft's [`mssql-tds`](https://github.com/microsoft/mssql-rs) crate.
4//! Migrate from tiberius with minimal code changes.
5//!
6//! This crate wraps `mssql-tds` (Microsoft's official Rust TDS protocol implementation)
7//! and provides the familiar tiberius-style API: named column access via `row.get::<T, _>("col")`,
8//! `into_first_result()`, positional `@P1, @P2` parameter binding, and a fluent [`Config`] builder.
9//!
10//! # Quick Start
11//!
12//! ```rust,no_run
13//! use mssql_tiberius_bridge::{Config, AuthMethod, Client};
14//!
15//! #[tokio::main]
16//! async fn main() -> mssql_tiberius_bridge::Result<()> {
17//! let mut cfg = Config::new();
18//! cfg.host("localhost")
19//! .port(1433)
20//! .database("master")
21//! .authentication(AuthMethod::sql_server("sa", "password"))
22//! .trust_cert();
23//!
24//! let mut client = Client::connect(&cfg).await?;
25//!
26//! // Simple query
27//! let rows = client
28//! .simple_query("SELECT name FROM sys.databases")
29//! .await?
30//! .into_first_result();
31//!
32//! for row in &rows {
33//! let name: &str = row.get("name").unwrap();
34//! println!("{name}");
35//! }
36//!
37//! // Parameterized query
38//! let rows = client
39//! .query("SELECT @P1 AS greeting, @P2 AS number", &[&"hello", &42i32])
40//! .await?
41//! .into_first_result();
42//!
43//! let greeting: &str = rows[0].get("greeting").unwrap();
44//! let number: i32 = rows[0].get("number").unwrap();
45//! println!("{greeting} {number}");
46//!
47//! Ok(())
48//! }
49//! ```
50//!
51//! # Feature Flags
52//!
53//! | Flag | Default | Description |
54//! |------|---------|-------------|
55//! | `json` | off | Enables [`serde_json::Value`] support for [`FromSql`] and [`ToSql`] |
56//! | `time` | off | Enables `time` crate support for [`FromSql`] and [`ToSql`] |
57//! | `jiff` | off | Enables `jiff` crate support for [`FromSql`] and [`ToSql`] |
58//! | `serde` | off | Enables `serde::Deserialize` for [`Row`] (see [`serde_de`]) |
59//! | `arrow` | off | Enables [`BulkInsert::send_arrow`](crate::bulk::BulkInsert::send_arrow) for Apache Arrow `RecordBatch` input (see [`bulk_arrow`]) |
60//!
61//! # Modules
62//!
63//! - [`client`] — [`Client`] wrapper with `simple_query`, `query`, `execute`
64//! - [`config`] — [`Config`] builder, [`AuthMethod`], [`EncryptionLevel`]
65//! - [`row`] — [`Row`] with named/indexed access, [`FromSql`] trait
66//! - [`query`] — [`QueryResult`], [`ToSql`] trait, [`ExecuteResult`]
67//! - [`column`] — [`Column`] metadata, [`ColumnType`] enum
68//! - [`pool`] — Connection pooling via [`deadpool`]
69//! - [`error`] — [`Error`] and [`Result`] types
70//!
71//! # Migration from tiberius
72//!
73//! See the [README](https://github.com/saurabh500/mssql-tiberius-bridge#migration-from-tiberius)
74//! for a full migration table. Key differences:
75//!
76//! - TCP transport is handled internally — no `TcpStream` boilerplate
77//! - `row.get::<&str, _>("col")` works (strings are pre-decoded from UTF-16)
78//! - Connection pooling via [`TdsManager`] + [`deadpool`]
79
80pub mod bulk;
81#[cfg(feature = "arrow")]
82pub mod bulk_arrow;
83pub mod client;
84pub mod column;
85pub mod config;
86pub mod error;
87pub mod pool;
88pub mod query;
89pub mod row;
90#[cfg(feature = "serde")]
91pub mod serde_de;
92
93// Re-exports for ergonomic top-level access.
94pub use bulk::{BulkInsert, BulkLoadRow, ColumnMapping, ColumnMappingSource};
95pub use client::Client;
96pub use column::{Collation, Column, ColumnType, MultiPartName};
97pub use config::{AuthMethod, Config, EncryptionLevel, Transport};
98pub use error::{Error, Result};
99pub use pool::{Pool, PooledConnection, TdsManager};
100pub use query::{DebugParams, ExecuteResult, QueryResult, ToSql};
101pub use row::{ColumnIndex, FromSql, Row};
102
103// Re-export mssql-tds types that consumers might need for advanced use.
104/// The underlying mssql-tds client type, exposed for advanced operations
105/// via [`Client::inner_mut()`].
106pub use mssql_tds::connection::tds_client::TdsClient;
107/// Raw column values from mssql-tds, exposed for low-level access
108/// via [`Row::raw_value()`].
109pub use mssql_tds::datatypes::column_values::ColumnValues;
110/// Decimal/Numeric value representation from mssql-tds.
111/// Returned inside `ColumnValues::Decimal` and `ColumnValues::Numeric`.
112pub use mssql_tds::datatypes::decoder::DecimalParts;