From 91dbda2c0dae963bdcc487dbf4430c928bb02c9a Mon Sep 17 00:00:00 2001 From: Olli Warro Date: Tue, 19 Mar 2024 14:43:04 +0200 Subject: [PATCH] add support for ReturnValuesOnConditionCheckFailure --- package.json | 2 +- src/nodes/deleteNode.ts | 3 ++- src/nodes/returnValuesNode.ts | 5 +++++ src/queryBuilders/deleteItemQueryBuilder.ts | 19 +++++++++++++++++++ src/queryCompiler/queryCompiler.ts | 4 ++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 74d1490..13c689b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/nodes/deleteNode.ts b/src/nodes/deleteNode.ts index 8c9dd51..4ccf687 100644 --- a/src/nodes/deleteNode.ts +++ b/src/nodes/deleteNode.ts @@ -1,6 +1,6 @@ import { ExpressionNode } from "./expressionNode"; import { KeysNode } from "./keysNode"; -import { ReturnValuesNode } from "./returnValuesNode"; +import { ReturnOldValuesNode, ReturnValuesNode } from "./returnValuesNode"; import { TableNode } from "./tableNode"; export type DeleteNode = { @@ -8,5 +8,6 @@ export type DeleteNode = { readonly table: TableNode; readonly conditionExpression: ExpressionNode; readonly returnValues?: ReturnValuesNode; + readonly returnValuesOnConditionCheckFailure?: ReturnOldValuesNode; readonly keys?: KeysNode; }; diff --git a/src/nodes/returnValuesNode.ts b/src/nodes/returnValuesNode.ts index d413ccd..5759f12 100644 --- a/src/nodes/returnValuesNode.ts +++ b/src/nodes/returnValuesNode.ts @@ -9,3 +9,8 @@ export type ReturnValuesNode = { readonly kind: "ReturnValuesNode"; readonly option: ReturnValuesOptions; }; + +export type ReturnOldValuesNode = { + readonly kind: "ReturnValuesNode"; + readonly option: Extract; +}; diff --git a/src/queryBuilders/deleteItemQueryBuilder.ts b/src/queryBuilders/deleteItemQueryBuilder.ts index 01c0a09..b8d5400 100644 --- a/src/queryBuilders/deleteItemQueryBuilder.ts +++ b/src/queryBuilders/deleteItemQueryBuilder.ts @@ -88,6 +88,10 @@ export interface DeleteItemQueryBuilderInterface< option: Extract ): DeleteItemQueryBuilderInterface; + returnValuesOnConditionCheckFailure( + option: Extract + ): DeleteItemQueryBuilderInterface; + keys & PickSkRequired>( pk: Keys ): DeleteItemQueryBuilderInterface; @@ -161,6 +165,21 @@ export class DeleteItemQueryBuilder< }); } + returnValuesOnConditionCheckFailure( + option: Extract + ): DeleteItemQueryBuilderInterface { + return new DeleteItemQueryBuilder({ + ...this.#props, + node: { + ...this.#props.node, + returnValuesOnConditionCheckFailure: { + kind: "ReturnValuesNode", + option, + }, + }, + }); + } + keys & PickSkRequired>( keys: Keys ) { diff --git a/src/queryCompiler/queryCompiler.ts b/src/queryCompiler/queryCompiler.ts index 108b936..83c919c 100644 --- a/src/queryCompiler/queryCompiler.ts +++ b/src/queryCompiler/queryCompiler.ts @@ -153,6 +153,8 @@ export class QueryCompiler { const { table: tableNode, returnValues: returnValuesNode, + returnValuesOnConditionCheckFailure: + returnValuesOnConditionCheckFailureNode, keys: keysNode, conditionExpression: conditionExpressionNode, } = deleteNode; @@ -170,6 +172,8 @@ export class QueryCompiler { TableName: tableNode.table, Key: keysNode?.keys, ReturnValues: returnValuesNode?.option, + ReturnValuesOnConditionCheckFailure: + returnValuesOnConditionCheckFailureNode?.option, ConditionExpression: compiledConditionExpression ? compiledConditionExpression : undefined,