Created
July 18, 2018 18:09
-
-
Save TiwaryAyush/5faa4b3fe0cf64a0d1404e70906255d9 to your computer and use it in GitHub Desktop.
Scanamo Operations
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
/** | |
* CRUD | |
**/ | |
def put(employee : Employee) : Future[Option[Either[DynamoReadError, Employee]]] = | |
ScanamoAlpakka.put[Employee](client)(TableName)(employee) | |
def get(name : String, id : Long) : Future[Option[Either[DynamoReadError, Employee]]] = | |
ScanamoAlpakka.get[Employee](client)(TableName)('name -> name and 'id -> id) | |
def delete(name : String, id : Long) : Future[DeleteItemResult] = | |
ScanamoAlpakka.delete[Employee](client)(TableName)('name -> name and 'id -> id) | |
def scan : Future[List[Either[DynamoReadError, Employee]]] = //also there is method called scan with limits | |
ScanamoAlpakka.scan[Employee](client)(TableName) | |
def query(name : String) : Future[List[Either[DynamoReadError, Employee]]] = | |
ScanamoAlpakka.query[Employee](client)(TableName)('name -> name and 'id > 0) | |
def update(employee : Employee) : Future[Either[DynamoReadError, Employee]] = | |
ScanamoAlpakka.update[Employee](client)(TableName)( | |
'name -> employee.name and 'id -> employee.id, | |
set('code -> employee.code) | |
) | |
/** | |
* Batch Operations*/ | |
def putAll(employees : Set[Employee]) : Future[List[BatchWriteItemResult]] = | |
ScanamoAlpakka.putAll[Employee](client)(TableName)(employees) | |
def getAll(names : Set[String]) : Future[Set[Either[DynamoReadError, Employee]]] = | |
ScanamoAlpakka.getAll[Employee](client)(TableName)('name -> names) | |
def deleteAll(names : Set[String]) : Future[List[BatchWriteItemResult]] = | |
ScanamoAlpakka.deleteAll(client)(TableName)('name -> names) | |
/** | |
* Conditional*/ | |
def putIfNotExist(employee : Employee) : Future[Either[ConditionalCheckFailedException, PutItemResult]] = { | |
ScanamoAlpakka.exec(client)(table.given(not(attributeExists('name))) | |
.put(employee)) | |
} | |
def deleteIfExist(employee : Employee) : Future[Either[ConditionalCheckFailedException, DeleteItemResult]] = { | |
ScanamoAlpakka.exec(client)(table.given('id > 0) | |
.delete('name -> employee.name)) | |
} | |
def updateIfExist(employee : Employee) : Future[Either[ScanamoError, Employee]] = { | |
ScanamoAlpakka.exec(client)(table.given('id > 0) | |
.update('name -> employee.name, | |
set('code -> employee.code))) | |
} | |
/** | |
* Filters*/ | |
def scanWithId(id : Long) : Future[List[Either[DynamoReadError, Employee]]] = { | |
ScanamoAlpakka.exec(client)(table | |
.filter('id -> id) | |
.scan()) | |
} | |
def queryWithId(code : String) : Future[List[Either[DynamoReadError, Employee]]] = { | |
ScanamoAlpakka.exec(client)(table | |
.filter('code -> Code(List(code))) | |
.query('name -> "name")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment