>_EXECUTIVE SUMMARY
stryke-mssql is an opt-in connector package in the stryke ecosystem — a Microsoft SQL Server / Azure SQL client. It exposes parametrized query and execute, transaction batches, scalar/exists helpers, and schema introspection as the Mssql package, against any SQL Server 2012+ or Azure SQL.
The client is tiberius, the pure-Rust TDS protocol implementation — no FreeTDS, no ODBC, no system driver. The cdylib owns one tokio runtime and presents a blocking facade, and ships once on demand rather than being linked into stryke core.
~DRIVER + BLOCKING FACADE
The client is tiberius, the pure-Rust TDS protocol implementation — no FreeTDS, no ODBC, no system driver. tiberius is async, so the cdylib owns one multi-thread tokio runtime and block_ons each call. From stryke's perspective every Mssql::* function is an ordinary blocking call; the async machinery is entirely internal.
~CONNECTION CACHE
One Client is cached per (host, port, database, auth, encrypt) tuple behind an async mutex, so repeated queries reuse the authenticated TDS session. A call that returns an error evicts its connection from the cache, so the next call reconnects cleanly instead of reusing a poisoned stream.
$ROW CONVERSION
SQL Server result sets are dynamically typed at the wire level. Rather than match every TDS column type, each cell is converted to JSON by trying the candidate Rust types in order — bool, i32, i64, f32, f64, string, decimal, uuid, datetime, date, time, binary — and taking the first that the driver accepts. Decimals serialize as strings to keep full precision, binary as base64, and datetimes as ISO-8601. Arbitrary queries round-trip without the caller declaring a schema.
&PARAMETERS + TRANSACTIONS
Parametrized statements use @P1, @P2, … placeholders; JSON params (null / bool / integer / float / string) are bound positionally, so values never enter the SQL text — no string interpolation, no injection surface. batch wraps a list of statements in BEGIN TRANSACTION … COMMIT on a single connection, rolling back if any statement fails.
| Group | Functions |
|---|---|
| Liveness | version, ping, server_version |
| Query | query, query_one, scalar, exists, simple_query |
| Write | execute, insert (multi-row), batch (transaction) |
| DDL | create_table, drop_table, truncate |
| Introspection | databases, tables, columns, views, schemas, primary_keys, foreign_keys, indexes, table_exists, current_database, count, row_count |
| SQL helpers | quote_ident, quote_literal, valid_identifier, escape_like, format_value, format_in_list, split_batch |
| URL helpers | parse_url, redact_url, build_url |
@CONNECTION RESOLUTION
Connection params arrive as a JSON hash on each call. Discrete keys are read with documented defaults; when neither url nor host is supplied and $MSSQL_URL is set, that ADO connection string is used as the fallback. The resolved tuple (host, port, database, auth, encrypt) is the cache key.
| Key | Default | Notes |
|---|---|---|
host | 127.0.0.1 | Server host. |
port | 1433 | TDS port. |
database | login default | Initial database for the session. |
username / password | — | SQL authentication. |
encrypt | required | required / off / not_supported → TDS EncryptionLevel. |
trust_cert | off | Truthy accepts a self-signed server certificate (dev). |
url | — | ADO string; overrides the discrete keys. Falls back to $MSSQL_URL. |
!LOAD MODEL (FFI)
Each export is a #[no_mangle] extern "C" fn mssql__* taking a JSON string and returning a JSON string. The lib/Mssql.stk wrapper builds the request hash, calls the symbol, and decodes the reply — an { error } payload becomes a Mssql::<fn>: <reason> exception. On first use Mssql, stryke dlopens the cdylib and registers the symbols declared in stryke.toml's [ffi].exports via rust_ffi::load_cdylib; only declared symbols resolve.
=PURE HELPERS (UNIT-TESTED)
The SQL- and URL-shaping helpers take no connection and are exercised by the in-crate test suite, so the injection-safety logic runs without a database.
| Helper | Behavior |
|---|---|
quote_ident | name → [name], doubling any ]. Schema-qualified names quote each dot segment. |
quote_literal | v → 'v', doubling any '. |
valid_identifier | True for [A-Za-z_][A-Za-z0-9_]*. |
escape_like | %/_/[ → [%]/[_]/[[] classes (no ESCAPE clause). |
format_value | string→'…', number→as-is, bool→1/0, null→NULL; arrays/objects error. |
format_in_list | scalars → (a, b, …); empty → (NULL). |
split_batch | Splits on lines that are only GO (case-insensitive); drops empties. |
parse_url / redact_url / build_url | ADO string ↔ map; password/pwd redacted to ***. |
/DEPENDENCIES
tiberius (TDS, rustls TLS), tokio + tokio-util (runtime + compat), chrono / rust_decimal / uuid for typed values, serde_json for the FFI payloads. Pure-Rust throughout — no native client library.
#PROJECT METADATA
| Item | Value |
|---|---|
| Version | 0.7.0 |
| License | MIT |
| Repository | github.com/MenkeTechnologies/stryke-mssql |
| Parent language | strykelang |
| Meta umbrella | MenkeTechnologiesMeta |
| Issues | github.com/MenkeTechnologies/stryke-mssql/issues |