Closed ericmarcos closed 3 years ago
Thanks for the excellent issue description. I can reproduce this and will get back to you with diagnosis soon.
Okay, diagnosed this issue.
The core issue is the handling of value templates was not taking into account dependent fields. i.e. the UUID needed to be generated before preparing the PK field. The fix is to calculate the order of dependencies in the properties and to calculate the property values according to that order.
There was an associated issue with create
when a PK/SK is not fully provided in the API properties.
We'll add a samples directory with a sample modeled on your bug code for verification.
See latest commit for the fix and for the samples/crud
Fixed in 1.4.2
FYI: DynamoDB won't let you write empty strings.
So
gs1sk: { type: String, value: '' },
Should always have a non-empty value.
Also, if you prefer, once defining the UUID in the table, each field can use
uuid: true
to use the Table level setting, which you set to 'ulid'.
Last tip, define a logger to see the actual generated DynamoDB code.
Add this to your Table params:
logger: (type, message, context) => {
if (type == 'trace' || type == 'data') return
console.log(type, message, JSON.stringify(context, null, 4))
}
@mobsense Thanks for the quick fix! I just tested it and it works now =)
I've applied your tips as well, however now I'm facing a new problem: I can't create a Table from my app. I used to create the table via CLI before, but I'd like to do it all programatically. I've opened a new issue (#43) for this so I'm closing this one.
Describe the bug I'm evaluating dynamodb-onetable for a project and I can't seem to make it work, even for just a basic "create" operation, please see code sample below.
To Reproduce
I compile this script with Babel:
babel index.js --out-dir dist
And run it with
node dist/index.js
Which results in this error:
I've also tried to set all the attributes of the model:
and a get another error:
Expected behavior A User item is created
Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
Additional context I'm using the local version of DynamoDB (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html)