Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using default on non-saved attributes when parsing query results #551

Open
Jimmy89 opened this issue Jun 30, 2023 · 4 comments
Open

Using default on non-saved attributes when parsing query results #551

Jimmy89 opened this issue Jun 30, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested

Comments

@Jimmy89
Copy link

Jimmy89 commented Jun 30, 2023

Hello all,

I have the following issue:
I have an entity called CreatedAt, storing for specific types a CreatedAt record (for a specific sortkey lookup). One of my attributes is named createdAt, which is the timestamp stored within the ULID (stored within the id field).

I thought I could be smart (and saving a few bits of dynamodb space) by not storing the createdAt attribute, but to calculate it based on the id like this:


// Entity details
attributes: {
   // Other attributes, including `id`
   createdAt: { type: "number", map: "CA", dependsOn: ["id"], transform: (_, {id}) => epochIntoISO(parseId(id).epoch, true), default: ({id}) => epochIntoISO(parseId(id).epoch, true), save: false }, // For clarity, first I mapped it to a CA attribute, but then I added `save: false`.
}

I was expecting that when I use the CreatedAt.query( /* query details */ ) the parsed record would contain a createdAt attribute as well. Unfortunately, it does not. I was hoping it would fire the default, but I guess because there is no CA attribute, it does not trigger this. Is there a way to resolve this issue?

@naorpeled
Copy link
Collaborator

Hey @Jimmy89,
Afaik, we don't support virtual fields.
Meaning you'd need to store it in DDB,
default is used in put and update operations,
transform is called only when fields are not undefined.

Definitely something we should be adding.
Will discuss this with Thomas and Jeremy and see if they think it's worth adding this to this version or only v1.

@naorpeled naorpeled added enhancement New feature or request question Further information is requested good first issue Good for newcomers labels Jun 30, 2023
@rakesh9541
Copy link

can you assign this to me and tell me the file of it

@naorpeled
Copy link
Collaborator

naorpeled commented Jul 8, 2023

can you assign this to me and tell me the file of it

Hey @rakesh9541,
thanks for volunteering.
Sure, the thing is that I don't have a solid strategy for this yet 😢

If you want to work on something else in the meantime,
this pr is up for grabs.

@rakesh9541
Copy link

@naorpeled ok i will have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants