soujiro32167 / zio-dynamodb

Simple, type-safe, and efficient access to DynamoDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zio-dynamodb

Project Stage CI Release Snapshot Discord
Project stage CI Release Artifacts Snapshot Artifacts Badge-Discord

Summary

Simple, type-safe, and efficient access to DynamoDB

Documentation

Getting Started

// 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.

ZIO DynamoDB Microsite

Contributing

Documentation for contributors

Code of Conduct

See the Code of Conduct

Support

Come chat with us on Badge-Discord.

License

License

About

Simple, type-safe, and efficient access to DynamoDB

License:Apache License 2.0


Languages

Language:Scala 98.7%Language:JavaScript 1.2%Language:CSS 0.1%