mu-persistent: Utilities for interoperation between Mu and Persistent

[ apache, library, network ] [ Propose Tags ]

Please see the documentation.

[Skip to Readme]


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


Versions [RSS],,,
Dependencies base (>=4.12 && <5), monad-logger (>=0.3 && <0.4), mu-schema (>=0.3 && <0.4), persistent (>=2.10 && <3), resource-pool (>=0.2 && <0.3), resourcet (>=1.2 && <2), transformers (>=0.5 && <0.6) [details]
License Apache-2.0
Copyright Copyright © 2019-2020 < 47 Degrees>
Author Flavio Corpa, Alejandro Serrano
Revised Revision 1 made by AlejandroSerrano at 2023-01-06T10:00:38Z
Category Network
Home page
Bug tracker
Source repo head: git clone
Uploaded by AlejandroSerrano at 2020-11-19T09:00:03Z
Downloads 888 total (0 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 mu-persistent-

[back to package description]


This are some utilities to integrate easily with persistent while using Mu.


Say you have for example, the following Entity:

mkPersist sqlSettings [persistLowerCase|
  name T.Text
  age  Int32
  deriving Show Generic

But in your proto3, the Person message is defined as:

message PersonRequest {
  int64 identifier = 1;

message Person {
  PersonRequest pid = 1;
  string name = 2;
  int32 age = 3;

How can you derive the correct ToSchema instances that Mu needs to work with that nested Id that belongs to another message? 🤔

You can use WithEntityNestedId, along with a custom field mapping and DerivingVia to do all the work for you!

{-# language DerivingVia #-}

type PersonFieldMapping
  = '[ "personAge" ':-> "age", "personName" ':-> "name" ]

deriving via (WithEntityNestedId "Person" PersonFieldMapping (Entity Person))
  instance ToSchema Maybe PersistentSchema "Person" (Entity Person)

For a more complete example of usage, please check the example with persistent.