Object

com.gu.scanamo

Scanamo

Related Doc: package scanamo

Permalink

object Scanamo

Provides a simplified interface for reading and writing case classes to DynamoDB

To avoid blocking, use com.gu.scanamo.ScanamoAsync

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Scanamo
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def delete(client: AmazonDynamoDB)(tableName: String)(key: UniqueKey[_]): DeleteItemResult

    Permalink

    Deletes a single item from a table by a unique key

    Deletes a single item from a table by a unique key

    >>> case class Farm(animals: List[String])
    >>> case class Farmer(name: String, age: Long, farm: Farm)
    
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> import com.gu.scanamo.syntax._
    >>> val client = LocalDynamoDB.client()
    
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.put(client)("farmers")(Farmer("McGregor", 62L, Farm(List("rabbit"))))
    ...   Scanamo.delete(client)("farmers")('name -> "McGregor")
    ...   Scanamo.get[Farmer](client)("farmers")('name -> "McGregor")
    ... }
    None
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def exec[A](client: AmazonDynamoDB)(op: ScanamoOps[A]): Id[A]

    Permalink
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. def get[T](client: AmazonDynamoDB)(tableName: String)(key: UniqueKey[_])(implicit arg0: DynamoFormat[T]): Option[ValidatedNel[DynamoReadError, T]]

    Permalink

    >>> case class Farm(animals: List[String])
    >>> case class Farmer(name: String, age: Long, farm: Farm)
    
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> val client = LocalDynamoDB.client()
    
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.put(client)("farmers")(Farmer("Maggot", 75L, Farm(List("dog"))))
    ...   Scanamo.get[Farmer](client)("farmers")(UniqueKey(KeyEquals('name, "Maggot")))
    ... }
    Some(Valid(Farmer(Maggot,75,Farm(List(dog)))))

    or with some added syntactic sugar:

    >>> import com.gu.scanamo.syntax._
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.put(client)("farmers")(Farmer("Maggot", 75L, Farm(List("dog"))))
    ...   Scanamo.get[Farmer](client)("farmers")('name -> "Maggot")
    ... }
    Some(Valid(Farmer(Maggot,75,Farm(List(dog)))))

    Can also be used with tables that have both a hash and a range key:

    >>> case class Engine(name: String, number: Int)
    >>> LocalDynamoDB.withTable(client)("engines")('name -> S, 'number -> N) {
    ...   Scanamo.put(client)("engines")(Engine("Thomas", 1))
    ...   Scanamo.get[Engine](client)("engines")('name -> "Thomas" and 'number -> 1)
    ... }
    Some(Valid(Engine(Thomas,1)))
  12. def getAll[T](client: AmazonDynamoDB)(tableName: String)(keys: UniqueKeys[_])(implicit arg0: DynamoFormat[T]): List[ValidatedNel[DynamoReadError, T]]

    Permalink

    Returns all the items in the table with matching keys

    Returns all the items in the table with matching keys

    Results are returned in the same order as the keys are provided

    >>> case class Farm(animals: List[String])
    >>> case class Farmer(name: String, age: Long, farm: Farm)
    
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> val client = LocalDynamoDB.client()
    
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.putAll(client)("farmers")(List(
    ...     Farmer("Boggis", 43L, Farm(List("chicken"))), Farmer("Bunce", 52L, Farm(List("goose"))), Farmer("Bean", 55L, Farm(List("turkey")))
    ...   ))
    ...   Scanamo.getAll[Farmer](client)("farmers")(UniqueKeys(KeyList('name, List("Boggis", "Bean"))))
    ... }
    List(Valid(Farmer(Boggis,43,Farm(List(chicken)))), Valid(Farmer(Bean,55,Farm(List(turkey)))))

    or with some added syntactic sugar:

    >>> import com.gu.scanamo.syntax._
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.putAll(client)("farmers")(List(
    ...     Farmer("Boggis", 43L, Farm(List("chicken"))), Farmer("Bunce", 52L, Farm(List("goose"))), Farmer("Bean", 55L, Farm(List("turkey")))
    ...   ))
    ...   Scanamo.getAll[Farmer](client)("farmers")('name -> List("Boggis", "Bean"))
    ... }
    List(Valid(Farmer(Boggis,43,Farm(List(chicken)))), Valid(Farmer(Bean,55,Farm(List(turkey)))))

    You can also retrieve items from a table with both a hash and range key

    >>> case class Doctor(actor: String, regeneration: Int)
    >>> LocalDynamoDB.withTable(client)("doctors")('actor -> S, 'regeneration -> N) {
    ...   Scanamo.putAll(client)("doctors")(
    ...     List(Doctor("McCoy", 9), Doctor("Ecclestone", 10), Doctor("Ecclestone", 11)))
    ...   Scanamo.getAll[Doctor](client)("doctors")(('actor and 'regeneration) -> List("McCoy" -> 9, "Ecclestone" -> 11))
    ... }
    List(Valid(Doctor(McCoy,9)), Valid(Doctor(Ecclestone,11)))
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. def put[T](client: AmazonDynamoDB)(tableName: String)(item: T)(implicit arg0: DynamoFormat[T]): PutItemResult

    Permalink

    Puts a single item into a table

    Puts a single item into a table

    >>> case class Farm(animals: List[String])
    >>> case class Farmer(name: String, age: Long, farm: Farm)
    
    >>> import com.gu.scanamo.syntax._
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> val client = LocalDynamoDB.client()
    
    >>> LocalDynamoDB.withTable(client)("farmers")('name -> S) {
    ...   Scanamo.put(client)("farmers")(Farmer("McDonald", 156L, Farm(List("sheep", "cow"))))
    ...   Scanamo.get[Farmer](client)("farmers")('name -> "McDonald")
    ... }
    Some(Valid(Farmer(McDonald,156,Farm(List(sheep, cow)))))
  20. def putAll[T](client: AmazonDynamoDB)(tableName: String)(items: List[T])(implicit arg0: DynamoFormat[T]): List[BatchWriteItemResult]

    Permalink

    Gets a single item from a table by a unique key

    Gets a single item from a table by a unique key

    >>> case class Rabbit(name: String)
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> LocalDynamoDB.withTable(client)("rabbits")('name -> S) {
    ...   Scanamo.putAll(client)("rabbits")((
    ...   for { _ <- 0 until 100 } yield Rabbit(util.Random.nextString(500))).toList)
    ...   Scanamo.scan[Rabbit](client)("rabbits").toList.size
    ... }
    100
  21. def query[T](client: AmazonDynamoDB)(tableName: String)(query: Query[_])(implicit arg0: DynamoFormat[T]): Streaming[ValidatedNel[DynamoReadError, T]]

    Permalink

    Perform a query against a table

    Perform a query against a table

    This can be as simple as looking up by a hash key where a range key also exists

    >>> case class Animal(species: String, number: Int)
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> val tableResult = LocalDynamoDB.createTable(client)("animals")('species -> S, 'number -> N)
    
    >>> val r1 = Scanamo.put(client)("animals")(Animal("Wolf", 1))
    >>> val r2 = for { i <- 1 to 3 } Scanamo.put(client)("animals")(Animal("Pig", i))
    >>> Scanamo.query[Animal](client)("animals")(Query(KeyEquals('species, "Pig"))).toList
    List(Valid(Animal(Pig,1)), Valid(Animal(Pig,2)), Valid(Animal(Pig,3)))

    or with some syntactic sugar

    >>> import com.gu.scanamo.syntax._
    >>> Scanamo.query[Animal](client)("animals")('species -> "Pig").toList
    List(Valid(Animal(Pig,1)), Valid(Animal(Pig,2)), Valid(Animal(Pig,3)))

    It also supports various conditions on the range key

    >>> Scanamo.query[Animal](client)("animals")('species -> "Pig" and 'number < 3).toList
    List(Valid(Animal(Pig,1)), Valid(Animal(Pig,2)))
    
    >>> Scanamo.query[Animal](client)("animals")('species -> "Pig" and 'number > 1).toList
    List(Valid(Animal(Pig,2)), Valid(Animal(Pig,3)))
    
    >>> Scanamo.query[Animal](client)("animals")('species -> "Pig" and 'number <= 2).toList
    List(Valid(Animal(Pig,1)), Valid(Animal(Pig,2)))
    
    >>> Scanamo.query[Animal](client)("animals")('species -> "Pig" and 'number >= 2).toList
    List(Valid(Animal(Pig,2)), Valid(Animal(Pig,3)))
    
    >>> case class Transport(mode: String, line: String)
    >>> LocalDynamoDB.withTable(client)("transport")('mode -> S, 'line -> S) {
    ...   Scanamo.putAll(client)("transport")(List(
    ...     Transport("Underground", "Circle"),
    ...     Transport("Underground", "Metropolitan"),
    ...     Transport("Underground", "Central")))
    ...   Scanamo.query[Transport](client)("transport")('mode -> "Underground" and ('line beginsWith "C")).toList
    ... }
    List(Valid(Transport(Underground,Central)), Valid(Transport(Underground,Circle)))
  22. def queryIndex[T](client: AmazonDynamoDB)(tableName: String, indexName: String)(query: Query[_])(implicit arg0: DynamoFormat[T]): Streaming[ValidatedNel[DynamoReadError, T]]

    Permalink

    Query a table using a secondary index

    Query a table using a secondary index

    >>> case class Transport(mode: String, line: String, colour: String)
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> import com.gu.scanamo.syntax._
    
    >>> LocalDynamoDB.withTableWithSecondaryIndex(client)("transport", "colour-index")('mode -> S, 'line -> S)('colour -> S) {
    ...   Scanamo.putAll(client)("transport")(List(
    ...     Transport("Underground", "Circle", "Yellow"),
    ...     Transport("Underground", "Metropolitan", "Maroon"),
    ...     Transport("Underground", "Central", "Red")))
    ...   Scanamo.queryIndex[Transport](client)("transport", "colour-index")('colour -> "Maroon").toList
    ... }
    List(Valid(Transport(Underground,Metropolitan,Maroon)))
  23. def scan[T](client: AmazonDynamoDB)(tableName: String)(implicit arg0: DynamoFormat[T]): Streaming[ValidatedNel[DynamoReadError, T]]

    Permalink

    Lazily scans a table

    Lazily scans a table

    Does not cache results by default

    >>> case class Bear(name: String, favouriteFood: String)
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    
    >>> LocalDynamoDB.withTable(client)("bears")('name -> S) {
    ...   Scanamo.put(client)("bears")(Bear("Pooh", "honey"))
    ...   Scanamo.put(client)("bears")(Bear("Yogi", "picnic baskets"))
    ...   Scanamo.scan[Bear](client)("bears").toList
    ... }
    List(Valid(Bear(Pooh,honey)), Valid(Bear(Yogi,picnic baskets)))

    Pagination is handled internally with Streaming result retrieving pages as necessary

    >>> case class Lemming(name: String, stuff: String)
    
    >>> LocalDynamoDB.withTable(client)("lemmings")('name -> S) {
    ...   Scanamo.putAll(client)("lemmings")(
    ...     (for { _ <- 0 until 100 } yield Lemming(util.Random.nextString(500), util.Random.nextString(5000))).toList
    ...   )
    ...   Scanamo.scan[Lemming](client)("lemmings").toList.size
    ... }
    100
  24. def scanIndex[T](client: AmazonDynamoDB)(tableName: String, indexName: String)(implicit arg0: DynamoFormat[T]): Streaming[ValidatedNel[DynamoReadError, T]]

    Permalink

    Returns a stream of all items present in the index

    Returns a stream of all items present in the index

    >>> case class Bear(name: String, favouriteFood: String, alias: Option[String])
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    
    >>> LocalDynamoDB.withTableWithSecondaryIndex(client)("bears", "alias-index")('name -> S)('alias -> S) {
    ...   Scanamo.put(client)("bears")(Bear("Pooh", "honey", Some("Winnie")))
    ...   Scanamo.put(client)("bears")(Bear("Yogi", "picnic baskets", None))
    ...   Scanamo.scanIndex[Bear](client)("bears", "alias-index").toList
    ... }
    List(Valid(Bear(Pooh,honey,Some(Winnie))))
  25. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  26. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  27. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped