// STRYKE-MSSQL — ENGINEERING REPORT

Opt-in stryke connector package v0.7.0 · cdylib libstryke_mssql · namespace Mssql · 36 functions · JSON-in/JSON-out FFI over dlopen

>_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.

Mssql
stryke namespace
opt-in
Tier
cdylib
Load model (dlopen)
TDS
Driver (tiberius, rustls)
36
Exported functions
v0.7.0
Package version
2012+
Min SQL Server / Azure SQL

~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 TRANSACTIONCOMMIT on a single connection, rolling back if any statement fails.

GroupFunctions
Livenessversion, ping, server_version
Queryquery, query_one, scalar, exists, simple_query
Writeexecute, insert (multi-row), batch (transaction)
DDLcreate_table, drop_table, truncate
Introspectiondatabases, tables, columns, views, schemas, primary_keys, foreign_keys, indexes, table_exists, current_database, count, row_count
SQL helpersquote_ident, quote_literal, valid_identifier, escape_like, format_value, format_in_list, split_batch
URL helpersparse_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.

KeyDefaultNotes
host127.0.0.1Server host.
port1433TDS port.
databaselogin defaultInitial database for the session.
username / passwordSQL authentication.
encryptrequiredrequired / off / not_supported → TDS EncryptionLevel.
trust_certoffTruthy accepts a self-signed server certificate (dev).
urlADO 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.

HelperBehavior
quote_identname[name], doubling any ]. Schema-qualified names quote each dot segment.
quote_literalv'v', doubling any '.
valid_identifierTrue for [A-Za-z_][A-Za-z0-9_]*.
escape_like%/_/[[%]/[_]/[[] classes (no ESCAPE clause).
format_valuestring→'…', number→as-is, bool→1/0, null→NULL; arrays/objects error.
format_in_listscalars → (a, b, …); empty → (NULL).
split_batchSplits on lines that are only GO (case-insensitive); drops empties.
parse_url / redact_url / build_urlADO 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

ItemValue
Version0.7.0
LicenseMIT
Repositorygithub.com/MenkeTechnologies/stryke-mssql
Parent languagestrykelang
Meta umbrellaMenkeTechnologiesMeta
Issuesgithub.com/MenkeTechnologies/stryke-mssql/issues