hmssql

hmssql

hmssql is a native Haskell client for Microsoft SQL Server (2017 and later) and Azure SQL Database. It implements SQL Server's wire protocol directly (TDS 7.4 and 8.0), so no ODBC driver or client library is needed.

The query API resembles postgresql-simple's, except that a query and its parameters are one value, so query conn q params becomes query conn q. A Query is SQL text with its parameters, and a Monoid, so SQL assembled at runtime from pieces such as "WHERE id = " <> param x refers to its parameters correctly however it was put together; the sp_executesql style with @p1, @p2, ... and a tuple or record of parameters works as well. Rows decode into records with a derived FromSqlRow, or into tuples, with the column types checked before the first row; queryS streams rows from the socket through the streaming package, in flat memory for any result size. Several statements go in one round trip, and bulk copy loads a table by the protocol's bulk load.

SQL Server's types are decoded faithfully, datetimeoffset and decimal included. Azure SQL's strict encryption (TDS 8.0) is supported alongside the older negotiated TLS, with certificate validation by default. Interrupting a call with an asynchronous exception (timeout, killThread) cancels the statement on the server and leaves the connection usable.

The design follows hpgsql; the protocol code descends from ms-tds and mssql-simple. hmssql was largely written and tested with AI, directed and reviewed by the maintainer; the README at https://github.com/joeyadams/hmssql says more.

Modules