import zio._
import zio.clock.Clock
import zio.schema.{ DeriveSchema, Schema }
import zio.dynamodb._
import zio.dynamodb.DynamoDBQuery._
import io.github.vigoo.zioaws.dynamodb
import io.github.vigoo.zioaws.dynamodb.DynamoDb
import io.github.vigoo.zioaws.core.config
import io.github.vigoo.zioaws.http4s
final case class Student(email: String, subject: String)
object Student {
implicit lazy val schema: Schema[Student] = DeriveSchema.gen[Student]
}
object Main extends App {
private val liveDynamoDbLayer: ZLayer[Any, Throwable, DynamoDb] =
http4s.default >>> config.default >>> dynamodb.live
val avi = Student("avi@gmail.com", "maths")
val adam = Student("adam@gmail.com", "english")
def run(args: List[String]) = {
(for {
_ <- (put("student", avi) zip put("student", adam)).execute
listOfStudentsOrError <- forEach(List(avi, adam)) { student =>
get[Student]("student",
PrimaryKey("email" -> student.email, "subject" -> student.subject)
)}.execute
} yield ())
.provideLayer((liveDynamoDbLayer ++ Clock.live) >>> DynamoDBExecutor.live)
.exitCode
}
}