mvasyliv / zio-dynamodb

Simple, type-safe, and efficient access to DynamoDB

Home Page:https://zio.dev/zio-dynamodb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZIO DynamoDB

Simple, type-safe, and efficient access to DynamoDB

Experimental CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO DynamoDB

Introduction

ZIO DynamoDB is a library that is used for type-safe, efficient, and boilerplate free access to AWS's DynamoDB service. It provides a type-safe API for many query types and the number of type-safe APIs is expanding. ZIO DynamoDB will automatically batch queries and execute unbatchable queries in parallel.

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

Installation

To use ZIO DynamoDB, we need to add the following lines to our build.sbt file:

libraryDependencies ++= Seq(
  "dev.zio" %% "zio-dynamodb" % "0.2.4"
)

Example

For examples please see examples sbt module. Below is Main.scala from that module:

import zio.aws.core.config
import zio.aws.{ dynamodb, netty }
import zio.dynamodb.DynamoDBQuery.{ get, put }
import zio.dynamodb.{ DynamoDBExecutor, PrimaryKey }
import zio.schema.{ DeriveSchema, Schema }
import zio.ZIOAppDefault

object Main extends ZIOAppDefault {

  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("personTable", examplePerson).execute
    person <- get[Person]("personTable", PrimaryKey("id" -> 1)).execute
    _      <- zio.Console.printLine(s"hello $person")
  } yield ()

  override def run =
    program.provide(
      netty.NettyHttpClient.default,
      config.AwsConfig.default, // uses real AWS dynamodb
      dynamodb.DynamoDb.live,
      DynamoDBExecutor.live
    )
}

For examples on how to use the DynamoDBLocal in memory database please see the integration tests and StudentZioDynamoDbExample . Note before you run these you must first run the DynamoDBLocal docker container using the provided docker-compose file:

docker-compose -f docker/docker-compose.yml up -d

Dont forget to shut down the container after you have finished

docker-compose -f docker/docker-compose.yml down

Documentation

Learn more on the ZIO DynamoDB homepage!

Contributing

For the general guidelines, see ZIO contributor's guide.

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

https://zio.dev/zio-dynamodb

License:Apache License 2.0


Languages

Language:Scala 100.0%