1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! 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.
use AppError;
use TcpStream;
use ;
use ;
/// Re-exported so a hand-written `Repository<T>` implementation (see this
/// crate's own doc comment) can build query parameters / read `Row`
/// values without needing `tiberius` as a second, separately-versioned
/// direct dependency of its own.
pub use tiberius;
/// 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).
pub type MssqlClient = Client;
static CLIENT: = const_new;
/// 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.
/// 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.
///
/// `trust_cert()` is set unconditionally - this targets a local/dev SQL
/// Server instance the same way this framework's SQLite/MySQL/Postgres
/// support already does (none of them has a TLS-certificate-verification
/// story either); a hardened production deployment would need real
/// certificate handling this first cut doesn't attempt.
pub async
/// 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.
pub async