|
I have been using Single Table Design for quite a while using the Document Client. I generally append Is there a way I could do this more simply in ElectroDB with attribute Getters and Setters? Would I have to do this on each Entity within the single table or could it be done in some sort of context across all entities? Rather like #471 for the security context. |
Answered by
zirkelc
May 8, 2025
Replies: 1 comment 2 replies
|
You need to add the timestamps to all your entities. Here's how I do it: import {
Attribute,
} from 'electrodb';
export const TIMESTAMP_ATTRIBUTES = {
createdAt: {
type: 'string',
readOnly: true,
// required: true,
default: () => DateTime.now().iso(),
set: (value, schema) => {
return DateTime.now().iso();
},
},
updatedAt: {
type: 'string',
readOnly: true,
watch: '*',
set: (value, schema) => {
return DateTime.now().iso();
},
},
} as const satisfies { [attribute: string]: Attribute }; |
2 replies
Answer selected by
owain68
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to add the timestamps to all your entities. Here's how I do it: