clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

Use Reserved Words as Attributes with Expressions #114

Closed iDVB closed 6 years ago

iDVB commented 6 years ago

Can't seem to use expressions to ensure I can use reserved word for Attribute. ("title") As in the AWS example: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

But not sure if I'm doing it wrong, if dynogels doesnt support this... or if dynogels-promisified doesn't support it.

    createVideo: (_, args) => {
      const params = {};
      params.ProjectionExpression = "#t";
      params.ExpressionAttributeNames = { "#t": "title" };
      return Video.createAsync(args, params)
        .then(resp => {
          console.log("resp", resp);
          return resp.attrs;
        })
        .catch(err => {
          console.log("err", err);
        });
    }

I just keep getting

ValidationException: ExpressionAttributeNames can only be specified when using expressions

cdhowie commented 6 years ago

ProjectionExpression is not a parameter for PutItem requests; it is being ignored by DynamoDB. It only makes sense in the context of a read operation, and this is a write operation.

iDVB commented 6 years ago

Seems to work perfect when I remove the expressionAttributeName and set the ProjectionExpression = “title”? But then how do I get it to work if I have more then one attribute that is of a reserved words?

I know what I’m trying to do, but new to DynamoDb and of course Dynogels.

cdhowie commented 6 years ago

It "works perfect" because ProjectionExpression is being ignored. ProjectionExpression is used to transform records being fetched from the database.

You are using createAsync, which maps to a DynamoDB PutItem request. This is a write operation. PutItem does not understand ProjectionExpression because it makes no sense in the context of a write operation.

What are you actually trying to accomplish with ProjectionExpression?

iDVB commented 6 years ago

Sorry, I thought I was getting Dynamo error with using a reserved word for attribute ("title"). AWS docs said to do this to resolve... http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html which is what I was trying to do.

Looks like it was never a problem with the above code. I removed all the expression logic and as you said it had no effect. Now it just works. :P Might have been another issues at the time.

I took a 25hr DynamoDB course with acloud.guru and it never really covered expressions. Thanks for rubber ducking it with me though. Much appreciated.

cdhowie commented 6 years ago

Dynogels should automatically handle reserved words. If it does not, this would be a bug.