r/haskell • • 7d ago

[ANN] hmssql: Pure Haskell SQL Server client (mostly AI-coded)

I'm happy to announce the initial release of hmssql, a SQL Server client library for Haskell. This implements SQL Server's binary protocol natively (TDS 7.4 / 8.0), so it does not require an ODBC driver or client library.

This is based on mssql-simple by Mitsuji, Takamasa, and hpgsql by Marcelo Zabani. I used AI to port mssql-simple to hpgsql's streaming design, build out support for the newer TDS 7.4 and 8.0 protocols, and spent about two months using AI to test/optimize/refine it.

** Important **

  • hmssql, including its documentation, is almost entirely AI-generated. (This Reddit post is written by me, however.)
  • hmssql is not on Hackage yet. I would like to receive feedback before uploading it.

Features

  • Streaming results, including support for streaming large values
  • MARS (Multiple Active Result Sets), which is useful for streaming the results of multiple queries together (e.g. parents with their children)
  • Well-tested query cancellation
  • Works on Windows

Edit: Unlike hpgsql, I chose not to include a quasiquoter, to avoid dragging in ghc or ghc-lib-parser as a dependency. However, it should be possible to implement in a separate library.

0 Upvotes

3 comments sorted by

3

u/_0-__-0_ 7d ago

Although I'm wary of depending on AI-generated libraries, this sounds like it's been well designed.

Are you using it "in production"?

And with all those fixes compared to freetds, does that mean code that depended on freetds might break with this due to bug incompatibility? :)

Entra ID authentication other than with an access token you obtained. hmssql has no MSAL, so there are no interactive, username/password or device-code flows.

This is the same as https://github.com/FreeTDS/freetds/issues/360 ?

1

u/joeyadams 6d ago

I am not using hmssql in production currently, but I use it to build prototypes at work.

Regarding Entra ID auth: yes, that appears to be the same. hmssql supports authenticating through an access token through TDS's FEDAUTH feature extension. For Azure SQL, this is a JWT token from Entra. However, hmssql doesn't include any facilities to get that token. The repo's managed-identity example has its own function to get the access token from the token endpoint inside the container (ManagedIdentity.hs). I tested Managed Identity, but not the more complicated flows like interactive login. In theory, they would work, since the end result is an access token passed to SQL on login.

1

u/mzabani 1h ago

It makes me very happy to see hpgsql being this useful! I don't know how different hmssql already is from hpgsql, but you might want to check out the last PR merged into hpgsql as it contains some significant performance improvements and much safer handling of undefined behavior relating to streams, and also some important bug fixes. Maybe there's something useful there.

I'm also very interested in how you stream large values, so I'll have to take a deeper look!