valiant-mtl: MTL-style adapter for valiant

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

Provides valiant database operations as MTL-style functions that work in any monad with MonadReader pool m and MonadIO m constraints. Unlike the built-in Valiant.Monad (which is ReaderT Pool IO), this adapter composes with arbitrary monad stacks.

import Valiant.Mtl

myApp :: (HasPool m, MonadIO m) => m [User]
myApp = do
  users <- fetchAllMtl listUsers ()
  pure users

[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
werror

Enable -Werror for development builds.

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.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies base (>=4.17 && <5), mtl (>=2.2 && <2.4), pg-wire (>=0.2 && <0.3), time (>=1.12 && <1.15), transformers (>=0.6 && <0.7), valiant (>=0.1 && <0.2), vector (>=0.12 && <0.14) [details]
Tested with ghc ==9.10.3
License BSD-3-Clause
Author Josh Burgess
Maintainer joshburgess.webdev@gmail.com
Uploaded by joshburgess at 2026-04-30T12:29:07Z
Category Database
Home page https://github.com/joshburgess/valiant
Bug tracker https://github.com/joshburgess/valiant/issues
Source repo head: git clone https://github.com/joshburgess/valiant(adapters/valiant-mtl)
Distributions
Downloads 9 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-04-30 [all 1 reports]

Readme for valiant-mtl-0.1.0.1

[back to package description]

valiant-mtl

MTL-style adapter for valiant.

All operations work in any monad with HasPool m (a MonadReader-like class that exposes a Pool) and MonadIO m. Use this when your application lives in an mtl stack with a richer environment than just Pool.

Quick start

import Control.Monad.Reader
import Valiant (newPool, defaultPoolConfig, poolConnString)
import Valiant.Mtl

data AppEnv = AppEnv
  { appPool   :: Pool
  , appLogger :: Logger
  }

instance HasPool (ReaderT AppEnv IO) where
  getPool = asks appPool

myApp :: (HasPool m, MonadIO m) => m [User]
myApp = do
  users <- fetchAllMtl listUsers ()
  count <- fetchScalarMtl countUsers ()
  pure users

main :: IO ()
main = do
  pool   <- newPool defaultPoolConfig { poolConnString = "postgres://..." }
  logger <- newLogger
  runReaderT myApp (AppEnv pool logger)

What you get

  • class HasPool m where getPool :: m Pool
  • Query operations: fetchOneMtl, fetchAllMtl, fetchScalarMtl, fetchOneOrThrowMtl, fetchExistsMtl, forEachMtl
  • Command operations: executeMtl, executeReturningMtl, executeBatchMtl
  • Transactions: withTransactionMtl, withTransactionLevelMtl
  • Pool helpers: poolStatsMtl, withConnectionMtl

There is also a Valiant.Monad module re-exported from this package that provides the same operations specialised to ReaderT Pool IO.

See the valiant tutorial for Statement definitions and the valiant prepare workflow.