Skip to content

Commit

Permalink
feat(update): add support for native document client options ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioArnt committed Sep 27, 2019
1 parent 1294c07 commit 7ebc57d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/base-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,21 +412,32 @@ export default abstract class Model<T> {
public async update(
pk: Key,
sk_actions: Key | IUpdateActions,
actions?: IUpdateActions,
actions_options?: IUpdateActions | Partial<DocumentClient.UpdateItemInput>,
options?: Partial<DocumentClient.UpdateItemInput>,
): Promise<PromiseResult<DocumentClient.UpdateItemOutput, AWSError>> {
// Handle overloading
const sk: Key = isKey(sk_actions) ? sk_actions : null;
const updateActions: IUpdateActions = isKey(sk_actions) ? actions : sk_actions;
// Build updateItem params
let sk: Key;
let updateActions: IUpdateActions;
let nativeOptions: Partial<DocumentClient.UpdateItemInput>;
if (!isKey(sk_actions)) {
// 1st overload
sk = null;
updateActions = sk_actions;
nativeOptions = actions_options;
} else {
// 2nd iverload
sk = sk_actions;
updateActions = actions_options as IUpdateActions;
nativeOptions = options;
}
this.testKeys(pk, sk);
const params: DocumentClient.UpdateItemInput = {
TableName: this.tableName,
Key: this.buildKeys(pk, sk),
AttributeUpdates: buildUpdateActions(updateActions),
};
if (options) {
Object.assign(params, options);
if (nativeOptions) {
Object.assign(params, nativeOptions);
}
return this.documentClient.update(params).promise();
}
Expand Down

0 comments on commit 7ebc57d

Please sign in to comment.