add ExpressionLiteral for passing in raw expressions and placeholders #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new type called
ExpressionLiteral
, which allows you to pass raw DynamoDB expressions to any method that takes an expression. dynamo will merge your placeholders with its own, rewriting your expression a little bit to avoid clobbering our automatically generated placeholders.You can use either
$
or?
as the variable when passing this as an argument to functions likeFilterExpr
.Be careful with this, especially if you use it with Update or for conditional writes. Improper usage could open yourself up to injection attacks. I definitely do not recommend that. Think of this like using string concatenation to build SQL.
One of the major features of this library is abstracting placeholder management away from you. My hope is that most people won't have to use this, but it can be useful for certain things.
You can use this along with AWS's expression library. This is helpful for people who want to move from the official AWS SDK to ours, or vice-versa. Perhaps we will want to support this passing in objects from this package explicitly later on, but for now it's easy to convert between the two.
Another use case would be if you wanted to take DynamoDB expressions as user input for implementing search parameters. Why not take advantage of the JS library? 🤠