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 client = LocalDynamoDB.client() >>> val scanamo = Scanamo(client) >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ >>> import org.scanamo.syntax._ >>> import org.scanamo.auto._ >>> LocalDynamoDB.withRandomTableWithSecondaryIndex(client)( ... "mode" -> S, "line" -> S)("mode" -> S, "colour" -> S ... ) { (t, i) => ... val transport = Table[Transport](t) ... 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(i) ... .filter("line" beginsWith ("C")) ... .query("mode" -> "Underground") ... } yield somethingBeginningWithC.toList ... scanamo.exec(operations) ... } List(Right(Transport(Underground,Central,Red)), Right(Transport(Underground,Circle,Yellow)))
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 client = LocalDynamoDB.client() >>> val scanamo = Scanamo(client) >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ >>> import org.scanamo.syntax._ >>> import org.scanamo.auto._ >>> LocalDynamoDB.withRandomTableWithSecondaryIndex(client)( ... "mode" -> S, "line" -> S)("mode" -> S, "colour" -> S ... ) { (t, i) => ... val transport = Table[Transport](t) ... 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(i).limit(1).descending.query( ... ("mode" -> "Underground" and ("colour" beginsWith "Bl")) ... ) ... } yield somethingBeginningWithBl.toList ... scanamo.exec(operations) ... } List(Right(Transport(Underground,Picadilly,Blue)))
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 client = LocalDynamoDB.client() >>> val scanamo = Scanamo(client) >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ >>> import org.scanamo.syntax._ >>> import org.scanamo.auto._ >>> LocalDynamoDB.withRandomTableWithSecondaryIndex(client)("organisation" -> S, "repository" -> S)("language" -> S, "license" -> S) { (t, i) => ... val githubProjects = Table[GithubProject](t) ... 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(i).query("language" -> "Scala" and ("license" -> "MIT")) ... } yield scalaMIT.toList ... scanamo.exec(operations) ... } List(Right(GithubProject(typelevel,cats,Scala,MIT)), Right(GithubProject(tpolecat,tut,Scala,MIT)), Right(GithubProject(localytics,sbt-dynamodb,Scala,MIT)))
Performs a scan with the ability to introduce effects into the computation.
Performs a scan with the ability to introduce effects into the computation. This is
useful for huge tables when you don't want to load the whole of it in memory, but
scan it page by page, with a maximum of pageSize items per page.
DynamoDB will only ever return maximum 1MB of data per query, so pageSize is an
upper bound.
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() >>> val scanamo = Scanamo(client) >>> import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ >>> import org.scanamo.auto._ >>> LocalDynamoDB.withRandomTableWithSecondaryIndex(client)("name" -> S)("antagonist" -> S) { (t, i) => ... val table = Table[Bear](t) ... 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(i).scan() ... } yield antagonisticBears ... scanamo.exec(ops) ... } List(Right(Bear(Paddington,marmalade sandwiches,Some(Mr Curry))), Right(Bear(Yogi,picnic baskets,Some(Ranger Smith))))
Performs a scan with the ability to introduce effects into the computation.
Performs a scan with the ability to introduce effects into the computation. This is
useful for huge tables when you don't want to load the whole of it in memory, but
scan it page by page, with a maximum of pageSize items per page..
DynamoDB will only ever return maximum 1MB of data per scan, so pageSize is an
upper bound.
Performs a query with the ability to introduce effects into the computation.
Performs a query with the ability to introduce effects into the computation. This is useful for huge tables when you don't want to load the whole of it in memory, but scan it page by page.
To control how many maximum items to load at once, use queryPaginatedM
Performs a scan with the ability to introduce effects into the computation.
Performs a scan with the ability to introduce effects into the computation. This is useful for huge tables when you don't want to load the whole of it in memory, but scan it page by page.
To control how many maximum items to load at once, use scanPaginatedM
Represents a secondary index on a DynamoDB table.
Can be constructed via the index method on Table