effectful-opaleye: effectful support for high-level PostgreSQL operations via Opaleye.

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

See the README for an overview, or the documentation in Effectful.Opaleye.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4 && <5), effectful-core (>=2.3 && <2.6), effectful-postgresql (>=0.1 && <0.2), effectful-th (>=1.0.0.1 && <1.0.1), opaleye (>=0.9 && <0.11), postgresql-simple (>=0.7 && <0.8), product-profunctors (>=0.9 && <0.12) [details]
Tested with ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.4, ghc ==9.2.8, ghc ==9.4.2, ghc ==9.4.5, ghc ==9.6.1, ghc ==9.6.7, ghc ==9.8.2, ghc ==9.10.2
License BSD-3-Clause
Copyright Copyright(c) Frederick Pringle 2025
Author Frederick Pringle
Maintainer frederick.pringle@fpringle.com
Category Database
Home page https://github.com/fpringle/effectful-postgresql
Uploaded by fpringle at 2025-07-22T09:11:52Z
Distributions
Downloads 2 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for effectful-opaleye-0.1.0.0

[back to package description]

effectful-opaleye

This package provides an effectful effect for Opaleye operations.

It combines the very safe, high-level syntax of Opaleye, with the WithConnection abstraction of effectful-postgresql.

Effectful functions

In the Opaleye effect we can perform the 4 main operations permitted by Opaleye: query, insert, delete, and update.

{-# LANGUAGE Arrows #-}
import Control.Arrow
import Effectful.Opaleye as EO
import qualified Opaleye as O

insertAndList :: (EO.Opaleye :> es) => Eff es [User]
insertAndList = do
  EO.runInsert $ O.Insert userTable [User {firstName = "Nuala"}] O.rCount Nothing

  EO.runDelete $ O.Delete userTable isAdmin O.rCount

  EO.runUpdate $ O.Update userTable (\user -> user {updatedAt = O.now}) isAdmin O.rCount

  EO.runSelect $ proc () -> do
    user <- O.selectTable userTable -< ()
    O.restrict -< firstName user `O.in_` (O.toFields <$> ["Anna", "Boris", "Carla"])
    returnA -< user

Interpreters

To run the Opaleye effect we can use the WithConnection effect from effectful-postgresql:

import Effectful.PostgreSQL as EP
import Effectful.Opaleye as EO

doOpaleyeStuff :: (WithConnection :> es) => Eff es [User]
doOpaleyeStuff = EO.runOpaleyeWithConnection insertAndList

The WithConnection effect can then be dispatched using one of its interpreters. Or, to skip that entirely, we can just use runOpaleyeConnection:

doOpaleyeStuff :: PSQL.Connection -> Eff es [User]
doOpaleyeStuff conn = EO.runOpaleyeConnection conn insertAndList