From 416898eb5965840e1a7fdbb8111930f419a94531 Mon Sep 17 00:00:00 2001 From: Iltotore Date: Wed, 27 Dec 2023 16:02:45 +0100 Subject: [PATCH] docs: Add Doobie documentation --- README.md | 25 ++++++------- docs/_docs/modules/doobie.md | 69 ++++++++++++++++++++++++++++++++++++ docs/sidebar.yml | 1 + 3 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 docs/_docs/modules/doobie.md diff --git a/README.md b/README.md index 94cb383d..5797a759 100644 --- a/README.md +++ b/README.md @@ -90,18 +90,19 @@ ivy"io.github.iltotore::iron:version" ### Platform support -| Module | JVM | JS | Native | -|-----------------|-----|-----|--------| -| iron | ✔️ | ✔️ | ✔️ | -| iron-cats | ✔️ | ✔️ | ✔️ | -| iron-circe | ✔️ | ✔️ | ✔️ | -| iron-ciris | ✔️ | ✔️ | ✔️ | -| iron-decline | ✔️ | ✔️ | ✔️ | -| iron-jsoniter | ✔️ | ✔️ | ✔️ | -| iron-scalacheck | ✔️ | ✔️ | ❌ | -| iron-skunk | ✔️ | ✔️ | ✔️ | -| iron-zio | ✔️ | ✔️ | ❌ | -| iron-zio-json | ✔️ | ✔️ | ❌ | +| Module | JVM | JS | Native | +|-----------------|-----|----|--------| +| iron | ✔️ | ✔️ | ✔️ | +| iron-cats | ✔️ | ✔️ | ✔️ | +| iron-circe | ✔️ | ✔️ | ✔️ | +| iron-ciris | ✔️ | ✔️ | ✔️ | +| iron-decline | ✔️ | ✔️ | ✔️ | +| iron-doobie | ✔️ | ❌ | ❌ | +| iron-jsoniter | ✔️ | ✔️ | ✔️ | +| iron-scalacheck | ✔️ | ✔️ | ❌ | +| iron-skunk | ✔️ | ✔️ | ✔️ | +| iron-zio | ✔️ | ✔️ | ❌ | +| iron-zio-json | ✔️ | ✔️ | ❌ | ## Adopters diff --git a/docs/_docs/modules/doobie.md b/docs/_docs/modules/doobie.md new file mode 100644 index 00000000..34d3b7aa --- /dev/null +++ b/docs/_docs/modules/doobie.md @@ -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). \ No newline at end of file diff --git a/docs/sidebar.yml b/docs/sidebar.yml index c7b233c1..904ff056 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -22,6 +22,7 @@ subsection: - page: modules/circe.md - page: modules/ciris.md - page: modules/decline.md + - page: modules/doobie.md - page: modules/jsoniter.md - page: modules/skunk.md - page: modules/scalacheck.md