| Crates.io | mssql-types |
| lib.rs | mssql-types |
| version | 0.6.0 |
| created_at | 2025-12-17 22:54:36.278097+00 |
| updated_at | 2026-01-13 22:17:22.11677+00 |
| description | SQL Server to Rust type mappings and conversions |
| homepage | |
| repository | https://github.com/praxiomlabs/rust-mssql-driver |
| max_upload_size | |
| id | 1991259 |
| size | 143,720 |
SQL Server to Rust type mappings and conversions for the rust-mssql-driver project.
This crate provides bidirectional mapping between SQL Server data types and Rust types, handling encoding and decoding of values in TDS wire format.
| SQL Server Type | Rust Type | Feature |
|---|---|---|
BIT |
bool |
default |
TINYINT |
u8 |
default |
SMALLINT |
i16 |
default |
INT |
i32 |
default |
BIGINT |
i64 |
default |
REAL |
f32 |
default |
FLOAT |
f64 |
default |
DECIMAL/NUMERIC |
rust_decimal::Decimal |
decimal |
CHAR/VARCHAR |
String |
default |
NCHAR/NVARCHAR |
String |
default |
BINARY/VARBINARY |
Bytes |
default |
DATE |
chrono::NaiveDate |
chrono |
TIME |
chrono::NaiveTime |
chrono |
DATETIME2 |
chrono::NaiveDateTime |
chrono |
DATETIMEOFFSET |
chrono::DateTime<FixedOffset> |
chrono |
UNIQUEIDENTIFIER |
uuid::Uuid |
uuid |
JSON |
serde_json::Value |
json |
use mssql_types::{SqlValue, FromSql, ToSql};
// Convert Rust value to SQL value
let rust_val: i32 = 42;
let sql_val = rust_val.to_sql()?;
// Convert SQL value to Rust type
let sql_val = SqlValue::Int(42);
let rust_val: i32 = i32::from_sql(&sql_val)?;
// NULL handling with Option
let nullable: Option<i32> = None;
let sql_val = nullable.to_sql()?; // SqlValue::Null
| Flag | Default | Description |
|---|---|---|
chrono |
Yes | Date/time type support |
uuid |
Yes | UUID type support |
decimal |
Yes | Decimal type support via rust_decimal |
json |
No | JSON type support via serde_json |
ToSqlConvert Rust types to SQL values:
pub trait ToSql {
fn to_sql(&self) -> Result<SqlValue, TypeError>;
}
FromSqlConvert SQL values to Rust types:
pub trait FromSql: Sized {
fn from_sql(value: &SqlValue) -> Result<Self, TypeError>;
}
MIT OR Apache-2.0