Skip to main content

Overview

scanamo Scala version support CI

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 to Maven Central, so just add the following to your build.sbt:

libraryDependencies += "org.scanamo" %% "scanamo" % "1.0.1+22-5a0f5ff4-SNAPSHOT"

then, given a table and some case classes

import org.scanamo._
import org.scanamo.syntax._
import org.scanamo.generic.auto._
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType._

val client = LocalDynamoDB.syncClient()
val scanamo = Scanamo(client)
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: Table[Farmer] = Table("farmer")

scanamo.exec(table.put(Farmer("McDonald", 156L, Farm(List("sheep", "cow")))))
scanamo.exec(table.get("name" === "McDonald"))
// res1: Option[Either[DynamoReadError, Farmer]] = Some(
// Right(Farmer("McDonald", 156L, 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.