Maven Central Build Status Coverage Status Chat on 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

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

libraryDependencies ++= Seq(
  "com.gu" %% "scanamo" % "1.0.0-M6"
)

then, given a table and some case classes

import com.gu.scanamo._
import com.gu.scanamo.syntax._
 
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: com.gu.scanamo.Table[Farmer] = Table(farmer)

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

Scanamo.exec(client)(table.get('name -> "McDonald"))
// res1: Option[Either[com.gu.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.