-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from mappies/returnValue
Added .returning()
- Loading branch information
Showing
40 changed files
with
1,182 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,12 +53,13 @@ let user1 = await nodenamo.get(1).from(User).execute<User>(); | |
|
||
//Update the user | ||
user1.name = 'This One'; | ||
await nodenamo.update(user1).from(User).execute(); | ||
/* Returns { items: [ User { id: 1, name: 'This One', email: '[email protected]' } ], | ||
lastEvaluatedKey: undefined } */ | ||
let originalUser = await nodenamo.update(user1).from(User).returning(ReturnValue.AllOld).execute(); | ||
/* Returns User { id: 1, name: 'Some One', email: '[email protected]' } */ | ||
|
||
//List all users | ||
let users = await nodenamo.list().from(User).execute<User>(); | ||
/* Returns { items: [ User { id: 1, name: 'This One', email: '[email protected]' } ], | ||
lastEvaluatedKey: undefined } */ | ||
|
||
//Delete the user by id | ||
await nodenamo.delete(1).from(User).execute(); | ||
|
@@ -193,6 +194,44 @@ where: | |
* `range` is the prefix value of a range key defined by `@DBColumn({range:true})` | ||
* `indexName` is the name of an index to be used with the query. | ||
|
||
### <a name='Update'>Update an object</a> | ||
|
||
Get an object from DynamoDB by the object's ID | ||
|
||
```javascript | ||
// Update an object | ||
await nodenamo.update(object).from(T).execute<T>(); | ||
|
||
// Update an object with a condition expression | ||
await nodenamo.update(object).from(T).where(conditionExpression, expressionAttributeNames, expressionAttributeValues).execute<T>(); | ||
|
||
// Update an object and requesting for a return value. | ||
import { ReturnValue } from 'nodenamo'; | ||
|
||
await nodenamo.update(object).from(T).returning(ReturnValue.AllOld).execute<T>(); | ||
|
||
// Update an object with a version check | ||
await nodenamo.update(object).from(T).withVersionCheck().execute<T>(); | ||
|
||
/*** | ||
* All operations above can be chained together. | ||
***/ | ||
await nodenamo.update(obj) | ||
.from(T) | ||
.where(conditionExpression, expressionAttributeNames, expressionAttributeValues) | ||
.withVersionCheck() | ||
.returning(ReturnValue.AllNew) | ||
.execute<T>(); | ||
|
||
``` | ||
|
||
where: | ||
* `obj` is an object retrieved from the <a href='#Get'>Get</a> or <a href='#List'>List</a> operations or an object created from a class decorated with `@DBTable()` | ||
* `T` is a class decorated with `@DBTable()` | ||
* `conditionExpression` is a string representing a conditional expression for DynamoDB's PUT operation. For example, `"#name = :name"` | ||
* `expressionAttributeNames` is an object representing attribute names for the conditionExpression. For example, `{ '#name': 'name' }` | ||
* `expressionAttributeValues` is an object representing attribute values for the conditionExpression. For example, `{ ':name': 'Some One' }` | ||
|
||
### Delete an object<a name='Delete'></a> | ||
|
||
Delete an object from DynamoDB by the object's ID. | ||
|
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
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
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
Oops, something went wrong.