TypeScript library: DynamoDB document API wrapper that handles value/name expressions for you
github.com/evanandrewrose/slick-dynamodbPosted May 11, 2022, 1:48 PM UTC
Posted May 11, 2022, 1:48 PM UTC
We have problems with DynamoDB's obtuse API as well. Our solution uses tagged template literals, I recommend taking a look for your project!
The code we write looks like this: { count: expr`if_not_exists(count, ${0}) + ${1}` },
I recommend giving them a shot! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
The library is too wrapped up in internal logic to opensource at this time but the implementation is simple. Here's the types for expr to get you started: export function expr(strings: TemplateStringsArray, ...placeholders: (number | string)[]): ... {
We use a regexp to generate ExpressionAttributeNames, it just turns any instances of #identifier into an expression name of the same content without the first character.
You should check out something like dynamodb-onetable or dynamodb-toolbox
Just wanted to share this library I wrote. It's my first NPM package. It enables users to provide dynamo expressions with inline attribute names/values, so instead of writing:
You can instead write:
I really love using TypeScript. Some of this code would've been really hard to get right without types. Since my library handles generating
ExpressionAttributeNamesandExpressionAttributeValuesfor you, I was able to just create new types where I omit those properties and then I replaced the{Condition, Update, etc.}Expressiontypes with my own type (the new input).I welcome feedback!