dynamodb-toolbox
dynamodb-toolbox copied to clipboard
receive "Error: 'alias' must be a unique string" when overriding created default value
i get this error when trying to override the created/modified default values as shown in the readme to make mocking easier
attributes: {
...
created: { default: () => new Date(Date.now()).toISOString() },
...
}
if I switch to this then the override is ignored
attributes: {
...
_ct: { default: () => new Date(Date.now()).toISOString() },
...
}
This is likely due to the fact that created
is the alias for _ct
. I’ll look into this to see if there’s a fix or add it to the documentation.
On this topic I get this error when trying to set created as a composite sort key, so I can order by created date.
created: ['sk', 1],
Not sure if we can look at this at the same time? Let me know if I am using it incorrectly.
Thanks for your great library!
On this topic I get this error when trying to set created as a composite sort key, so I can order by created date.
created: ['sk', 1],
Have you tried using default
instead of composite keys? I moved all of my stuff from composites to defaults because I find it more intuitive/explicit.
@darbio
Thanks mate, seems to be a reasonable solution. Also thanks for the quick reply very helpful.
dependsOn: ['created'],
default: (data) => `${data.programSubscriptionId}${data.created}`
@jeremydaly the docs for this one still need to be updated
well, I first tried:
timestamps: true,
created: "createdAt",
modified: "updatedAt",
then I would still get created / modified
instead of createdAt / modifiedAt
.
so I tried this:
timestamps: true,
created: "createdAt",
modified: "updatedAt",
createdAlias: "createdAt",
modifiedAlias: "updatedAt",
and I got an error:
✖ Error: 'alias' must be a unique string
The final solution was:
timestamps: true,
attributes: {
createdAt: { type: "string", dependsOn: ["created"], default: (data) => `${data.created}` },
updatedAt: { type: "string", dependsOn: ["modified"], default: (data) => `${data.modified}`, onUpdate: true}
},
this ended up creating 4 properties: _ct, _mt, createdAt, updatedAt
.
any remarks on this??