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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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


[Skip to Readme]

Properties

Versions 0.1.0.0
Change log None available
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]
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-05-27T07:41:33Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


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 Connection 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