mu-haskell/adapter/persistent
2020-11-20 11:15:47 +01:00
..
src/Mu/Adapter Fix GraphQL example + pools in mu-persistent (#261) 2020-11-17 10:05:19 +01:00
hie.yaml Make ghcide happy (#49) 2019-12-19 14:41:57 +01:00
LICENSE Extract mu-persistent to it's own package! ✂️ (#47) 2019-12-18 08:50:17 +01:00
mu-persistent.cabal ♻️ Run cabal-fmt and extract library example (#264) 2020-11-20 10:24:15 +01:00
README.md Extract mu-persistent to it's own package! ✂️ (#47) 2019-12-18 08:50:17 +01:00
Setup.hs ❄️ Add gitignore.nix to prevent Nix cache invalidation for trivial changes (#265) 2020-11-20 11:15:47 +01:00

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.