sam-goodwin / typesafe-dynamodb

TypeSafe type definitions for the AWS DynamoDB API
Apache License 2.0
205 stars 11 forks source link

ExpressionAttributeValues seem to not support props with underscores #58

Closed danikenan closed 6 days ago

danikenan commented 6 days ago

Seems like the string pattern used does not take into account underscores in property names.

Screenshot 2024-10-08 at 9 51 51

interface MyItem {
  key: string;
  noUnderscore: string;
  has_underscore: string;
}

const MyItemUpdateCommand = TypeSafeUpdateItemCommand<MyItem, 'key', undefined>();

async function updateIt1(key: string, value: string) {
  return dynamo.send(
    new MyItemUpdateCommand({
      TableName: 'MyItemTable',
      Key: { key: { S: key } },
      UpdateExpression: `set noUnderscore = :noUnderscore`,
      ExpressionAttributeValues: { ':noUnderscore': { S: value } },
    })
  );
}

async function updateIt2(key: string, value: string) {
  return dynamo.send(
    new MyItemUpdateCommand({
      TableName: 'MyItemTable',
      Key: { key: { S: key } },
      UpdateExpression: `set has_underscore = :has_underscore`,
      ExpressionAttributeValues: { ':has_underscore': { S: value } },
    })
  );
}
sam-goodwin commented 6 days ago

Thanks for reporting, it does indeed look like there's a problem in how identifiers were being parsed. Fixed in: https://github.com/sam-goodwin/typesafe-dynamodb/pull/59

sam-goodwin commented 6 days ago

Should be fixed in v0.8.1, LMK if it works!