Library Integration

This section shows examples on how to integrate snowflake4s with other libraries.

Circe

sbt
libraryDependencies += "io.github.qwbarch" %% "snowflake4s-circe" % "1.1.0-RC1"
Maven
<properties>
  <scala.binary.version>3</scala.binary.version>
</properties>
<dependencies>
  <dependency>
    <groupId>io.github.qwbarch</groupId>
    <artifactId>snowflake4s-circe_${scala.binary.version}</artifactId>
    <version>1.1.0-RC1</version>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "3"
]
dependencies {
  implementation "io.github.qwbarch:snowflake4s-circe_${versions.ScalaBinary}:1.1.0-RC1"
}

The circe module provides an encoder/decoder for snowflakes.

import io.circe.syntax.given
import io.github.qwbarch.snowflake4s.circe.syntax.given
import io.github.qwbarch.snowflake4s.Snowflake

val snowflake = Snowflake(123456789L)
val encoded = snowflake.asJson
val decoded = encoded.as[Snowflake]

Skunk

sbt
libraryDependencies += "io.github.qwbarch" %% "snowflake4s-skunk" % "1.1.0-RC1"
Maven
<properties>
  <scala.binary.version>3</scala.binary.version>
</properties>
<dependencies>
  <dependency>
    <groupId>io.github.qwbarch</groupId>
    <artifactId>snowflake4s-skunk_${scala.binary.version}</artifactId>
    <version>1.1.0-RC1</version>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "3"
]
dependencies {
  implementation "io.github.qwbarch:snowflake4s-skunk_${versions.ScalaBinary}:1.1.0-RC1"
}

The skunk module provides a codec for snowflakes.

import skunk.Command
import skunk.syntax.all.sql
import io.github.qwbarch.snowflake4s.skunk.codec.snowflake

val command: Command[Snowflake] = sql"DELETE FROM messages WHERE id=$snowflake".command

Http4s

sbt
libraryDependencies += "io.github.qwbarch" %% "snowflake4s-http4s" % "1.1.0-RC1"
Maven
<properties>
  <scala.binary.version>3</scala.binary.version>
</properties>
<dependencies>
  <dependency>
    <groupId>io.github.qwbarch</groupId>
    <artifactId>snowflake4s-http4s_${scala.binary.version}</artifactId>
    <version>1.1.0-RC1</version>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "3"
]
dependencies {
  implementation "io.github.qwbarch:snowflake4s-http4s_${versions.ScalaBinary}:1.1.0-RC1"
}

The http4s module provides an extractor for handling path parameters, as well as an implicit required for a query parameter matcher.

import org.http4s.dsl.io.*
import org.http4s.HttpRoutes
import cats.effect.IO
import cats.syntax.all.given
import io.github.qwbarch.snowflake4s.http4s.syntax.given
import io.github.qwbarch.snowflake4s.Snowflake

val routes: HttpRoutes[IO] = HttpRoutes.of[IO] {
   case GET -> Root / SnowflakeVar(snowflake) => Ok(snowflake.show)
   case GET -> Root / "user" :? SnowflakeQueryParamMatcher(snowflake) => Ok(snowflake.show)
}