Description
Utilities for interoperation between Mu and Persistent.
Description
Please see the readme file.
README.md
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.