Skip to main content

Crate larust_mssql

Crate larust_mssql 

Source
Expand description

SQL Server support via a hand-written [larust_repository::Repository] implementation, one per model - not a larust_orm::Backend variant. sqlx has no Microsoft SQL Server driver at all (confirmed by reading its own source during this crate’s design: sqlx-core’s only MSSQL-shaped code is permanently-dead, pre-0.8 scaffolding, and no mssql Cargo feature has ever existed to enable it), so SQL Server structurally cannot join the sqlx::Any/Backend/QueryBuilder architecture the way SQLite/MySQL/Postgres do. This crate connects through tiberius - a separate, pure-Rust TDS-protocol client with its own connection type, its own @P1/@P2 parameter syntax, and no shared code with larust-orm at all.

Explicit ceiling, stated plainly, not oversold: CRUD only. No #[derive(Model)] codegen, no relations, no xr migrate, no QueryBuilder-style chaining - the same trade-off larust_repository::Repository’s own doc comment already documents for “a backend sqlx::Any structurally cannot reach.” This crate owns only the connection plumbing below; writing an actual Repository<T> implementation for your own model is real, per-model code you write by hand - there is no generic blanket impl<T> Repository<T> for AnyRepository<T> the way larust-orm has for SQL-family backends, for the same reason that type’s own doc comment gives: building INSERT/UPDATE text (or here, tiberius parameter bindings) from a struct’s fields needs to know those fields, which a function generic over T never does - only code written for that specific struct can. See tests/widget_repository.rs for a complete worked example against a real server, mirroring larust-repository’s own InMemoryRepository test in shape, just against tiberius instead of a HashMap.

The connection is a single, mutex-serialized tiberius::Client, not a real pool - tiberius has no built-in pooling. This serializes all SQL Server traffic in a process through one TDS session, a real and deliberately undisguised limitation for this first cut, not a glossed-over one. A proper pool (bb8/deadpool plus a hand-written tiberius adapter) is the natural follow-up if concurrent load against SQL Server ever becomes a real requirement - explicitly out of scope here.

Re-exports§

pub use tiberius;

Structs§

MssqlConfig
SQL Server connection settings - the same host/port/database/username/ password shape larust_orm::config::ConnectionConfig uses for the SQL-family backends, but deliberately not that type itself: tiberius doesn’t take a connection URL the way sqlx does, it takes its own tiberius::Config builder, so there’s no shared to_url()-style assembly to reuse here.

Functions§

client
Returns the process-wide client, locked for exclusive use - released automatically when the returned guard drops. See this crate’s own doc comment for why this is one mutex-serialized connection, not a pool. Errors (rather than panics) if connect hasn’t run yet - the same “a misconfigured startup order is a real possibility” reasoning larust_orm::pool() already documents for its own identical case.
connect
Connects and stores the client process-wide - same OnceCell singleton idiom larust_orm::pool()’s own OnceLock<AnyPool> uses. Call once at startup, before any Repository<T> implementation built on client runs.

Type Aliases§

MssqlClient
The concrete client type client hands back, locked. Compat< TcpStream> is tiberius’s own transport-agnostic Client running over a plain Tokio TCP stream via the tokio-util compatibility shim (tiberius is built against the futures AsyncRead/AsyncWrite traits, not Tokio’s own).