mu-persistent: Utilities for interoperation between Mu and Persistent

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the readme file.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.1.0, 0.3.1.0
Change log None available
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
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 AlejandroSerrano at 2020-11-19T09:00:01Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


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.