aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.09k stars 577 forks source link

Support DynamoDB expression builder #3165

Closed AllanZhengYP closed 1 year ago

AllanZhengYP commented 2 years ago

Is your feature request related to a problem? Please describe.

Many other AWS SDKs provide abstractions for DynamoDB expressions. They are more intuitive by providing mapping from variables to expression, and they also handle the encoding. Some examples from other AWS SDKs:

Currently the closest library provided by SDK team is the Expression package in DynamoDB data mapper, but it is more of a building block for the data mapper, with confusing interface for public consumption.

Describe the solution you'd like

Provide an expression builder similar to example above.

Issues:

spridev commented 2 years ago

Here are some existing JS/TS alternatives, using different approaches and syntaxes:

Looking at the existing official solutions above, I do personally like the builder pattern used in Java. This reminds me of the usual SQL query builders like Laravel Eloquent or Knex.js. Chainable methods, clean syntax, easy to understand.

Finally, I would rather not wrap the DynamoDBClient within another class, with a magic update method for example (like in Dynamon). I feel like the following approach gives more flexibility and control to the user:

const expr = new ExpressionBuilder().buildForUpdate();

const response = await ddb.send(
  new UpdateItemCommand({
    TableName: TABLE_NAME,
    Key: marshall({
      PK: 'USER#1234',
      SK: 'USER#1234',
    }),

    // Solution 1
    UpdateExpression: expr.content,
    ExpressionAttributeNames: expr.names,
    ExpressionAttributeValues: expr.values,

    // Solution 2
    ...expr
  })
);

Is this feature still pending or already in the roadmap? I think it's an important missing piece for the DynamoDB DX. Once the syntax has been determined, I will try to implement it, either here or as an independent package.

github-actions[bot] commented 1 year ago

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.