CI Coverage Release Issues Users Chat
Build Status Coverage Status Release Artifacts Average time to resolve an issue Scaladex dependencies badge Gitter

Scanamo is a library to make using DynamoDB with Scala simpler and less error-prone.

The main focus is on making it easier to avoid mistakes and typos by leveraging Scala’s type system and some higher level abstractions.

Quick start

Note: the LocalDynamoDB object is provided by the scanamo-testkit package.

Scanamo is published for Scala 2.11 and 2.12 to Maven Central, so just add the following to your build.sbt:

libraryDependencies += "com.gu" %% "scanamo" % "1.0.0-M8"

then, given a table and some case classes

import org.scanamo._
import org.scanamo.syntax._
import org.scanamo.auto._
 
val client = LocalDynamoDB.client()
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
val farmersTableResult = LocalDynamoDB.createTable(client)("farmer")('name -> S)

case class Farm(animals: List[String])
case class Farmer(name: String, age: Long, farm: Farm)

we can simply put and get items from Dynamo, without boilerplate or reflection

val table = Table[Farmer]("farmer")
// table: org.scanamo.Table[Farmer] = Table(farmer)

Scanamo.exec(client)(table.put(Farmer("McDonald", 156L, Farm(List("sheep", "cow")))))
// res0: Option[Either[org.scanamo.error.DynamoReadError,Farmer]] = None

Scanamo.exec(client)(table.get('name -> "McDonald"))
// res1: Option[Either[org.scanamo.error.DynamoReadError,Farmer]] = Some(Right(Farmer(McDonald,156,Farm(List(sheep, cow)))))

Scanamo supports most other DynamoDB operations, beyond the basic Put and Get.

The translation between Dynamo items and Scala types is handled by a type class called DynamoFormat.

Licensed under the Apache License, Version 2.0.