https://github.com/deamondev/doobie-mtl-example
Example of how to use Monad Transformers Library together with Doobie
https://github.com/deamondev/doobie-mtl-example
doobie error-handling monad mtl postgresql scala shell
Last synced: about 1 year ago
JSON representation
Example of how to use Monad Transformers Library together with Doobie
- Host: GitHub
- URL: https://github.com/deamondev/doobie-mtl-example
- Owner: DeamonDev
- Created: 2022-05-23T11:48:38.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T12:41:22.000Z (almost 4 years ago)
- Last Synced: 2025-01-16T08:39:54.369Z (about 1 year ago)
- Topics: doobie, error-handling, monad, mtl, postgresql, scala, shell
- Language: Scala
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Doobie-MTL
In this application I show how to manage (functional) error handling in the context of Doobie. We have database
`manifolds_atlas` with table `algebraic_varieties`. Each variety has its id, name, equation describing it and its euler characteristics.
If you are not familiar with algebraic topology / geometry you can think about it as an abstract nonsense ;)
## Prepare database (under postgres user)
To prepare database you just need to run the shell script
```shell
$ ./postgres.sh
```
## Two services
There are two services `ManifoldsAtlas` and `ManifoldsAtlasMTL`. To each of them we inject the DB connection. First one
deals with errors using ADT `Either[Error, *]`. The problem with this solution is that we need to lift critical errors (e.g.
database connector problems) to the domain errors. The second approach uses Typelevel's [MTL](https://typelevel.org/cats-mtl/getting-started.html)
to avoid such a lifting, allowing us to have two error channels. The one for domain errors (managed by ADT) and the one for critical errors
(injected, in a sense to an effect type).
This program was inspired after reading very good [article](https://guillaumebogard.dev/posts/functional-error-handling/?utm_source=pocket_mylist) written by Guillaume Bogard.