mu-persistent: Utilities for interoperation between Mu and Persistent

[ apache, library, network ] [ Propose Tags ]

Please see the documentation.


[Skip to Readme]

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

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.1.0
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 <http://47deg.com 47 Degrees>
Author Flavio Corpa, Alejandro Serrano
Maintainer flavio.corpa@47deg.com
Revised Revision 1 made by AlejandroSerrano at 2023-01-06T10:00:38Z
Category Network
Home page https://higherkindness.io/mu-haskell/db/
Bug tracker https://github.com/higherkindness/mu-haskell/issues
Source repo head: git clone https://github.com/higherkindness/mu-haskell
Uploaded by AlejandroSerrano at 2020-11-19T09:00:03Z
Distributions
Downloads 956 total (17 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-0.3.1.0

[back to package description]

mu-persistent

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

Usage

Say you have for example, the following Entity:

mkPersist sqlSettings [persistLowerCase|
Person
  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.