Skip to content

Commit

Permalink
add support for ReturnValuesOnConditionCheckFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed Mar 19, 2024
1 parent 46b406b commit 91dbda2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tsynamo",
"author": "woltsu",
"version": "0.0.6",
"version": "0.0.7",
"description": "Typed query builder for DynamoDB",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/deleteNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ExpressionNode } from "./expressionNode";
import { KeysNode } from "./keysNode";
import { ReturnValuesNode } from "./returnValuesNode";
import { ReturnOldValuesNode, ReturnValuesNode } from "./returnValuesNode";
import { TableNode } from "./tableNode";

export type DeleteNode = {
readonly kind: "DeleteNode";
readonly table: TableNode;
readonly conditionExpression: ExpressionNode;
readonly returnValues?: ReturnValuesNode;
readonly returnValuesOnConditionCheckFailure?: ReturnOldValuesNode;
readonly keys?: KeysNode;
};
5 changes: 5 additions & 0 deletions src/nodes/returnValuesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ export type ReturnValuesNode = {
readonly kind: "ReturnValuesNode";
readonly option: ReturnValuesOptions;
};

export type ReturnOldValuesNode = {
readonly kind: "ReturnValuesNode";
readonly option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">;
};
19 changes: 19 additions & 0 deletions src/queryBuilders/deleteItemQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export interface DeleteItemQueryBuilderInterface<
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilderInterface<DDB, Table, O>;

returnValuesOnConditionCheckFailure(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilderInterface<DDB, Table, O>;

keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(
pk: Keys
): DeleteItemQueryBuilderInterface<DDB, Table, O>;
Expand Down Expand Up @@ -161,6 +165,21 @@ export class DeleteItemQueryBuilder<
});
}

returnValuesOnConditionCheckFailure(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilderInterface<DDB, Table, O> {
return new DeleteItemQueryBuilder<DDB, Table, O>({
...this.#props,
node: {
...this.#props.node,
returnValuesOnConditionCheckFailure: {
kind: "ReturnValuesNode",
option,
},
},
});
}

keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(
keys: Keys
) {
Expand Down
4 changes: 4 additions & 0 deletions src/queryCompiler/queryCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class QueryCompiler {
const {
table: tableNode,
returnValues: returnValuesNode,
returnValuesOnConditionCheckFailure:
returnValuesOnConditionCheckFailureNode,
keys: keysNode,
conditionExpression: conditionExpressionNode,
} = deleteNode;
Expand All @@ -170,6 +172,8 @@ export class QueryCompiler {
TableName: tableNode.table,
Key: keysNode?.keys,
ReturnValues: returnValuesNode?.option,
ReturnValuesOnConditionCheckFailure:
returnValuesOnConditionCheckFailureNode?.option,
ConditionExpression: compiledConditionExpression
? compiledConditionExpression
: undefined,
Expand Down

0 comments on commit 91dbda2

Please sign in to comment.