Class

com.gu.scanamo

SecondaryIndex

Related Doc: package scanamo

Permalink

sealed abstract class SecondaryIndex[V] extends AnyRef

Represents a secondary index on a DynamoDB table.

Can be constructed via the index method on Table

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

Abstract Value Members

  1. abstract def filter[C](condition: C)(implicit arg0: ConditionExpression[C]): SecondaryIndex[V]

    Permalink

    Filter the results of scan or query within DynamoDB

    Filter the results of scan or query within DynamoDB

    Note that rows filtered out still count towards your consumed capacity

    >>> case class Transport(mode: String, line: String, colour: String)
    >>> val transport = Table[Transport]("transport")
    
    >>> 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)('mode -> S, 'colour -> S
    ... ) {
    ...   val operations = for {
    ...     _ <- transport.putAll(Set(
    ...       Transport("Underground", "Circle", "Yellow"),
    ...       Transport("Underground", "Metropolitan", "Magenta"),
    ...       Transport("Underground", "Central", "Red"),
    ...       Transport("Underground", "Picadilly", "Blue"),
    ...       Transport("Underground", "Northern", "Black")))
    ...     somethingBeginningWithC <- transport.index("colour-index")
    ...                                   .filter('line beginsWith ("C"))
    ...                                   .query('mode -> "Underground")
    ...   } yield somethingBeginningWithC.toList
    ...   Scanamo.exec(client)(operations)
    ... }
    List(Right(Transport(Underground,Central,Red)), Right(Transport(Underground,Circle,Yellow)))
  2. abstract def limit(n: Int): SecondaryIndex[V]

    Permalink

    Query or scan an index, limiting the number of items evaluated by Dynamo

    Query or scan an index, limiting the number of items evaluated by Dynamo

    >>> case class Transport(mode: String, line: String, colour: String)
    >>> val transport = Table[Transport]("transport")
    
    >>> 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)('mode -> S, 'colour -> S
    ... ) {
    ...   val operations = for {
    ...     _ <- transport.putAll(Set(
    ...       Transport("Underground", "Circle", "Yellow"),
    ...       Transport("Underground", "Metropolitan", "Magenta"),
    ...       Transport("Underground", "Central", "Red"),
    ...       Transport("Underground", "Picadilly", "Blue"),
    ...       Transport("Underground", "Northern", "Black")))
    ...     somethingBeginningWithBl <- transport.index("colour-index").limit(1).query(
    ...       ('mode -> "Underground" and ('colour beginsWith "Bl")).descending
    ...     )
    ...   } yield somethingBeginningWithBl.toList
    ...   Scanamo.exec(client)(operations)
    ... }
    List(Right(Transport(Underground,Picadilly,Blue)))
  3. abstract def query(query: Query[_]): ScanamoOps[List[Either[DynamoReadError, V]]]

    Permalink

    Run a query against keys in a secondary index

    Run a query against keys in a secondary index

    >>> case class GithubProject(organisation: String, repository: String, language: String, license: String)
    >>> val githubProjects = Table[GithubProject]("github-projects")
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    
    >>> import com.gu.scanamo.syntax._
    
    >>> LocalDynamoDB.withTableWithSecondaryIndex(client)("github-projects", "language-license")('organisation -> S, 'repository -> S)('language -> S, 'license -> S) {
    ...   val operations = for {
    ...     _ <- githubProjects.putAll(Set(
    ...       GithubProject("typelevel", "cats", "Scala", "MIT"),
    ...       GithubProject("localytics", "sbt-dynamodb", "Scala", "MIT"),
    ...       GithubProject("tpolecat", "tut", "Scala", "MIT"),
    ...       GithubProject("guardian", "scanamo", "Scala", "Apache 2")
    ...     ))
    ...     scalaMIT <- githubProjects.index("language-license").query('language -> "Scala" and ('license -> "MIT"))
    ...   } yield scalaMIT.toList
    ...   Scanamo.exec(client)(operations)
    ... }
    List(Right(GithubProject(typelevel,cats,Scala,MIT)), Right(GithubProject(tpolecat,tut,Scala,MIT)), Right(GithubProject(localytics,sbt-dynamodb,Scala,MIT)))
  4. abstract def scan(): ScanamoOps[List[Either[DynamoReadError, V]]]

    Permalink

    Scan a secondary index

    Scan a secondary index

    This will only return items with a value present in the secondary index

    >>> case class Bear(name: String, favouriteFood: String, antagonist: Option[String])
    
    >>> val client = LocalDynamoDB.client()
    >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
    >>> val table = Table[Bear]("bears")
    
    >>> import com.gu.scanamo.syntax._
    
    >>> LocalDynamoDB.withTableWithSecondaryIndex(client)("bears", "antagonist")('name -> S)('antagonist -> S) {
    ...   val ops = for {
    ...     _ <- table.put(Bear("Pooh", "honey", None))
    ...     _ <- table.put(Bear("Yogi", "picnic baskets", Some("Ranger Smith")))
    ...     _ <- table.put(Bear("Paddington", "marmalade sandwiches", Some("Mr Curry")))
    ...     antagonisticBears <- table.index("antagonist").scan()
    ...   } yield antagonisticBears
    ...   Scanamo.exec(client)(ops)
    ... }
    List(Right(Bear(Paddington,marmalade sandwiches,Some(Mr Curry))), Right(Bear(Yogi,picnic baskets,Some(Ranger Smith))))

Concrete 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. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

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

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

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped