Project Stage | CI | Release | Snapshot | Discord |
---|---|---|---|---|
Simple, type-safe, and efficient access to DynamoDB
// only snapshots are published at the moment
resolvers += Resolver.sonatypeRepo("snapshots")
// add zio-dynamodb to your dependencies - lookup the latest snapshot version here https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-dynamodb_2.13/
libraryDependencies ++= Seq(
// ...
"dev.zio" %% "zio-dynamodb" % "0.0.1<LATEST_VERSION>"
)
For examples please see examples sbt module. Below is Main.scala
from that module.
package zio.dynamodb.examples
import io.github.vigoo.zioaws.http4s
import zio.{ App, ExitCode, Has, URIO, ZLayer }
import zio.dynamodb.DynamoDBQuery.{ get, put }
import zio.dynamodb.{ DynamoDBExecutor, PrimaryKey }
import zio.schema.{ DeriveSchema, Schema }
import io.github.vigoo.zioaws.core.config
import io.github.vigoo.zioaws.dynamodb
import zio.clock.Clock
object Main extends App {
final case class Person(id: Int, firstName: String)
object Person {
implicit lazy val schema: Schema[Person] = DeriveSchema.gen[Person]
}
val examplePerson = Person(1, "avi")
private val program = for {
_ <- put("tableName", examplePerson).execute
person <- get[Person]("tableName", PrimaryKey("id" -> 1)).execute
_ <- zio.console.putStrLn(s"hello $person")
} yield ()
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
val dynamoDbLayer = http4s.default >>> config.default >>> dynamodb.live // uses real AWS dynamodb
val executorLayer = (dynamoDbLayer ++ ZLayer.identity[Has[Clock.Service]]) >>> DynamoDBExecutor.live
program.provideCustomLayer(executorLayer).exitCode
}
}
For examples on how to use the DynamoDBLocal in memory database please see the integration tests and StudentZioDynamoDbExample
Under the hood we use the excellent ZIO AWS library for type-safe DynamoDB access, and the awesome ZIO Schema library for schema derived codecs (see here for documentation on how to customise these through annotations).
Microsite content to come soon.
Documentation for contributors
See the Code of Conduct