esqueleto-compat: Compatibility operators for Persistent and Esqueleto

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

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.2.0
Change log ChangeLog.md
Dependencies base (>=4.13 && <5), conduit, esqueleto (<4), persistent, resourcet, transformers [details]
License BSD-3-Clause
Copyright 2023 Matt Parsons
Author Matt Parsons
Maintainer parsonsmatt@gmail.com
Revised Revision 2 made by parsonsmatt at 2024-05-02T16:39:05Z
Category Data
Home page https://github.com/parsonsmatt/esqueleto-compat#readme
Bug tracker https://github.com/parsonsmatt/esqueleto-compat/issues
Source repo head: git clone https://github.com/parsonsmatt/esqueleto-compat
Uploaded by parsonsmatt at 2023-10-20T16:22:39Z
Distributions NixOS:0.0.2.0
Downloads 56 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-10-20 [all 1 reports]

Readme for esqueleto-compat-0.0.2.0

[back to package description]

esqueleto-compat

This library aims to provide compatibility operators that can allow esqueleto and persistent to be imported together.

Operators like ==. and >=. are defined as class members, and you can use them in the same module. Functions like update that are shared in both libraries are given an E suffix for the esqueleto version. And functions for operating on SqlExpr are given an _ suffix when the name would otherwise be a conflict.

Example:

import Database.Esqueleto.Compat

foo :: MonadIO m => TableId -> SqlPersistT m ()
foo tableKey = do
    -- Esqueleto:
    updateE $ \table -> do
        set [table ^. TableField =. val "Hello"] table
        where_ $ table ^. TableId ==. val tableKey

    -- Persistent
    update tableKey [TableField =. "Goodbye"]

    -- Esqueleto:
    select $ do
        pure $ exists_ $ do
            t <- from $ table @Table
            where_ $ t ^. TableField ==. val "Hello"

    -- Persistent
    exists [TableField ==. val "Hello"]