Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philip Wills
committed
Feb 7, 2017
1 parent
9612ddd
commit efde186
Showing
6 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
layout: docs | ||
title: Asynchronous Requests | ||
position: 5 | ||
position: 6 | ||
--- | ||
|
||
## Non-blocking requests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
layout: docs | ||
title: Conditional Operations | ||
position: 3 | ||
--- | ||
|
||
## Conditional Operations | ||
|
||
Modifying operations ([Put](operations.html#put-and-get), [Delete](operations.html#delete), | ||
[Update](operations.html#update)) can be performed conditionally, so that they | ||
only have an effect if some state of the DynamoDB table is true at the time of | ||
execution. | ||
|
||
```tut:silent | ||
import com.gu.scanamo._ | ||
import com.gu.scanamo.syntax._ | ||
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ | ||
val client = LocalDynamoDB.client() | ||
case class Gremlin(number: Int, name: String, wet: Boolean, friendly: Boolean) | ||
``` | ||
```tut:book | ||
val gremlinsTable = Table[Gremlin]("gremlins") | ||
LocalDynamoDB.withTable(client)("gremlins")('number -> N) { | ||
val ops = for { | ||
_ <- gremlinsTable.putAll( | ||
Set(Gremlin(1, "Gizmo", false, true), Gremlin(2, "George", true, false))) | ||
// Only `put` Gremlins if not already one with the same number | ||
_ <- gremlinsTable.given(not(attributeExists('number))) | ||
.put(Gremlin(2, "Stripe", false, true)) | ||
_ <- gremlinsTable.given(not(attributeExists('number))) | ||
.put(Gremlin(3, "Greta", true, true)) | ||
allGremlins <- gremlinsTable.scan() | ||
_ <- gremlinsTable.given('wet -> true) | ||
.delete('number -> 1) | ||
_ <- gremlinsTable.given('wet -> true) | ||
.delete('number -> 2) | ||
_ <- gremlinsTable.given('wet -> true) | ||
.update('number -> 1, set('friendly -> false)) | ||
_ <- gremlinsTable.given('wet -> true) | ||
.update('number -> 3, set('friendly -> false)) | ||
remainingGremlins <- gremlinsTable.scan() | ||
} yield (allGremlins, remainingGremlins) | ||
Scanamo.exec(client)(ops) | ||
} | ||
``` | ||
|
||
More examples can be found in the [Table ScalaDoc](/scanamo/latest/api/com/gu/scanamo/Table.html#given[T](condition:T)(implicitevidence$2:com.gu.scanamo.query.ConditionExpression[T]):com.gu.scanamo.query.ConditionalOperation[V,T]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
layout: docs | ||
title: DynamoFormat | ||
position: 4 | ||
position: 5 | ||
--- | ||
|
||
## DynamoFormat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
layout: docs | ||
title: Using Indexes | ||
position: 3 | ||
position: 4 | ||
--- | ||
|
||
## Using Indexes | ||
|