Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 26f3c2a

Browse files
CarsonBradshawjeskew
authored andcommitted
Support combining function and math expressions
Resolves #122
1 parent 9a548f3 commit 26f3c2a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/dynamodb-expressions/src/MathematicalExpression.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {AttributeBearingExpression} from "./AttributeBearingExpression";
22
import {AttributePath} from "./AttributePath";
33
import {ExpressionAttributes} from "./ExpressionAttributes";
4+
import {FunctionExpression} from "./FunctionExpression";
45

5-
export type MathematicalExpressionOperand = AttributePath|string|number;
6+
export type MathematicalExpressionOperand = AttributePath|FunctionExpression|string|number;
67

78
const MATHEMATICAL_EXPRESSION_TAG = 'AmazonDynamoDbMathematicalExpression';
89
const EXPECTED_TOSTRING = `[object ${MATHEMATICAL_EXPRESSION_TAG}]`;
@@ -21,9 +22,14 @@ export class MathematicalExpression implements AttributeBearingExpression {
2122

2223
serialize(attributes: ExpressionAttributes) {
2324
const safeArgs = [this.lhs, this.rhs].map(
24-
arg => AttributePath.isAttributePath(arg) || typeof arg === 'string'
25-
? attributes.addName(arg)
26-
: attributes.addValue(arg)
25+
arg => {
26+
if (FunctionExpression.isFunctionExpression(arg)) {
27+
return arg.serialize(attributes);
28+
}
29+
return AttributePath.isAttributePath(arg) || typeof arg === 'string'
30+
? attributes.addName(arg)
31+
: attributes.addValue(arg);
32+
}
2733
);
2834
return `${safeArgs[0]} ${this.operator} ${safeArgs[1]}`;
2935
}

0 commit comments

Comments
 (0)