-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: "Doobie Support" | ||
--- | ||
|
||
# Doobie Support | ||
|
||
This module provides refined types Get/Put/Meta instances for [Doobie](https://tpolecat.github.io/doobie/). | ||
|
||
## Dependency | ||
|
||
SBT: | ||
|
||
```scala | ||
libraryDependencies += "io.github.iltotore" %% "iron-doobie" % "version" | ||
``` | ||
|
||
Mill: | ||
|
||
```scala | ||
ivy"io.github.iltotore::iron-doobie:version" | ||
``` | ||
|
||
### Following examples' dependencies | ||
|
||
SBT: | ||
|
||
```scala | ||
libraryDependencies += "org.tpolecat" %% "doobie-core" % "1.0.0-RC4" | ||
``` | ||
|
||
Mill: | ||
|
||
```scala | ||
ivy"org.tpolecat::doobie-core::1.0.0-RC4" | ||
``` | ||
|
||
## Get/Put/Meta instances | ||
|
||
```scala | ||
import doobie.* | ||
import doobie.implicits.* | ||
|
||
import io.github.iltotore.iron.* | ||
import io.github.iltotore.iron.constraint.all.* | ||
import io.github.iltotore.iron.doobie.given | ||
|
||
opaque type CountryCode = Int :| Positive | ||
object CountryCode extends RefinedTypeOps[Int, Positive, CountryCode] | ||
|
||
opaque type CountryName = String :| Not[Blank] | ||
object CountryName extends RefinedTypeOps[String, Not[Blank], CountryName] | ||
|
||
opaque type Population = Int :| Positive | ||
object Population extends RefinedTypeOps[Int, Positive, Population] | ||
|
||
//Refined columns of a table | ||
case class Country(code: CountryCode, name: CountryName, pop: Population) | ||
|
||
//Interpolation with refined values | ||
def biggerThan(minPop: Population) = | ||
sql""" | ||
select code, name, population, indepyear | ||
from country | ||
where population > $minPop | ||
""".query[Country] | ||
``` | ||
|
||
Example inspired by | ||
[another one from Doobie's documentation](https://tpolecat.github.io/doobie/docs/06-Checking.html#checking-a-query). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters