hasql-check-ghc: Check inferred hasql statements with what GHC knows of their types

[ bsd3, database, development, library, program ] [ Propose Tags ] [ Report a vulnerability ]

The types of a statement of Hasql.Check.Inferred.TH are only known once GHC has type-checked its module. This package gets them from GHC in two ways: . * Hasql.Check.Plugin, a GHC plugin that checks the statements against a database while their module compiles, making a statement that does not fit the schema a compile error at its quote. . * hasql-check-hie, which reads them from the .hie files GHC writes with -fwrite-ide-info, for hasql-check --inferred. It needs no database, so it can run inside a sandboxed build. . Both depend on GHC's own library: build them with the GHC the checked project is built with.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
lint

lint

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.5.0.0, 0.5.1.0
Change log ChangeLog.md
Dependencies base (>=4.21 && <4.23), bytestring (>=0.11 && <0.13), containers (>=0.6 && <0.9), ghc (>=9.12 && <9.15), hasql-check (>=0.5 && <0.6), hasql-check-ghc, text (>=2.0 && <2.2) [details]
Tested with ghc ==9.12.4 || ==9.14.1
License BSD-3-Clause
Copyright 2026 Kronor
Author Pranay Sashank, Jose Lorenzo Rodriguez
Maintainer lorenzo@kronor.io, pranay.sashank@kronor.io
Uploaded by lorenzo at 2026-10-29T15:22:24Z
Category Database, Development
Home page https://github.com/kronor-io/hasql-check
Bug tracker https://github.com/kronor-io/hasql-check/issues
Source repo head: git clone https://github.com/kronor-io/hasql-check(ghc)
Distributions
Executables hasql-check-hie
Downloads 7 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2026-10-29 [all 2 reports]

Readme for hasql-check-ghc-0.5.0.0

[back to package description]

hasql-check-ghc

The GHC half of hasql-check.

Hasql.Check.Inferred.TH's quoters take no annotations: a statement's parameter and result types come from the Haskell type it is used at. GHC only knows those types once it has type-checked the module, which is after the quoter ran, so this package gets them from GHC itself:

  • Hasql.Check.Plugin, a GHC plugin that checks each statement against a database while its module compiles. Add it to the package that holds the statements:

    build-depends: hasql-check-ghc
    ghc-options:   -fplugin=Hasql.Check.Plugin
    

    and set HASQL_CHECK_DATABASE_URL. A statement that does not fit the schema is then a compile error at its quote. Without the variable nothing is checked; if the database cannot be reached the plugin says so once and the build carries on.

  • hasql-check-hie, which reads the same types out of the .hie files GHC writes with -fwrite-ide-info, for hasql-check --inferred:

    $ cabal build --ghc-options='-fwrite-ide-info -hiedir=.hie'
    $ hasql-check-hie $(find .hie -name '*.hie') > statements.jsonl
    $ hasql-check --inferred statements.jsonl --nullability --types
    

    It needs no database, so it can run inside a sandboxed build, such as a Nix derivation, with only the checking step outside it.

Both use GHC's own library, whose internals change with each release, so this package supports the series it has been built against — currently GHC 9.12 and 9.14. Build it with the GHC the checked project is built with.

The full documentation, including everything the checks report, is in the main README.

Development

cabal test compiles fixture modules with GHC itself, against a throwaway PostgreSQL server, so initdb, pg_ctl and psql must be on PATH. The compiler finds the plugin through the package environment cabal writes (write-ghc-environment-files: always, in the project's cabal.project), so run the tests from a checkout of the whole repository rather than from this directory's sdist.