mu-persistent: Utilities for interoperation between Mu and Persistent

[ apache, library, network ] [ Propose Tags ]

Please see the readme file.


[Skip to Readme]

Downloads

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.7 && <5), monad-logger, mu-schema (>=0.3.0), persistent, resourcet, transformers [details]
License Apache-2.0
Copyright Copyright © 2019-2020 <http://47deg.com 47 Degrees>
Author Flavio Corpa, Alejandro Serrano
Maintainer flavio.corpa@47deg.com
Category Network
Home page https://github.com/higherkindness/mu-haskell/persistent#readme
Bug tracker https://github.com/higherkindness/mu-haskell/issues
Source repo head: git clone https://github.com/higherkindness/mu-haskell
Uploaded by FlavioCorpa at 2020-04-28T11:59:35Z
Distributions
Downloads 960 total (15 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.0.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.