Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB interpreter #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

DynamoDB interpreter #34

wants to merge 4 commits into from

Conversation

smacker
Copy link

@smacker smacker commented Jan 10, 2022

With this PR I want to open a discussion about adding an interpreter for DynamoDB.

References:

The code is based on sql package and adapted.

I wonder if it is something you would be interested to merge? What else will we need to add if yes?

@stalniy
Copy link
Owner

stalniy commented Jan 14, 2022

Hey @smacker

First of all, well done! I'm pretty surprised that somebody managed to put own interpreter without much help :) Just wondering how do you plan to use it, together with casl or separately?

I will accept this PR after a bit closer look. Also, I think you need to add somewhere that it's a PartiQL interpreter. At first, for some reason, I expected to see object expressions interpreter.

@smacker
Copy link
Author

smacker commented Jan 19, 2022

Thank you. The code is rather simple and straightforward so it is not difficult.

We are planning to use it together with casl. Please take your time, no hurry.

Also, I think you need to add somewhere that it's a PartiQL interpreter

It is not. DynamoDB filter expressions look a lot like PartiQL but they are different. For example, in PartiQL one can write field LIKE '%value' but a filter expression is begins_with(field, 'value') or in PartiQL field IS NULL is a valid syntax but as a filter expression it should be written as attribute_not_exists(field).

The generated values should be passed to DocumentClient.query method as the following:

const dynamo = new DynamoDB.DocumentClient();

const [filterExpr, names, values] = interpret(conditions);
const input: DynamoDB.DocumentClient.QueryInput = {
  FilterExpression: filterExpr,
  ExpressionAttributeNames: names,
  ExpressionAttributeValues: values,
};
const result = await dynamo.query(input).promise();

Keep in mind dynamodb API also contains some deprecated parameters to do the same with a different syntax but they shouldn't be used:

export interface QueryInput {
  /**
   * This is a legacy parameter. Use FilterExpression instead. For more information, see QueryFilter in the Amazon DynamoDB Developer Guide.
   */
  QueryFilter?: FilterConditionMap;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants