# Experiments with Template Haskell, SQL, and Records

**URL:** <https://discourse.haskell.org/t/experiments-with-template-haskell-sql-and-records/14636>\
**Category:** Show and Tell\
**Created:** [September 2, 2026, 7:17pm UTC](https://discourse.haskell.org/t/experiments-with-template-haskell-sql-and-records/14636 "2026-09-02T19:17:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![olf](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/olf/32/3813_2.png) [@olf](https://discourse.haskell.org/u/olf)\
**Post date:** [September 2, 2026, 8:15pm UTC](https://discourse.haskell.org/t/experiments-with-template-haskell-sql-and-records/14636/2 "2026-09-02T20:15:55Z")

</div>

The problem of aligning Haskell types with a database schema has been solved from two different ends:

1. [persistent](https://www.yesodweb.com/book/persistent) has a [quasi-quoter](https://hackage-content.haskell.org/package/persistent-2.18.1.0/docs/Database-Persist-Quasi.html) that generate both the schema and the Haskell types for you, including encoders/decoders, from one definition. Since the query interface arising from that is not as easy to work with as it could, persistent has come out of fashion.
2. [pGenie](https://discourse.haskell.org/t/ann-pgenie-a-sql-first-code-generator-for-postgresql-no-dsls-no-orms-no-hand-rolled-codecs/13869) takes an existing database schema as first-class citizen and generates the Haskell types from that.

Your idea of parameterizing the record types is also found in [opaleye](https://hackage.haskell.org/package/opaleye). They also implicitly use HKD by instantiating all rank-0 parameters with type applications of the form `f a` uniformly in `f` but varying in `a`.

For those who, for some reason, wish to never write any SQL at all, a compatibility shim between persistent’s convenient quasi-quoter (generating monomorphic types) and opaleye’s wonderful parametric record types would be handy.

---

_[View the full topic](https://discourse.haskell.org/t/experiments-with-template-haskell-sql-and-records/14636)._
