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

anyway to view produced request from fluent apI? #210

Open
TheBreadGuy opened this issue May 26, 2023 · 5 comments
Open

anyway to view produced request from fluent apI? #210

TheBreadGuy opened this issue May 26, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@TheBreadGuy
Copy link

is there any way to see what is being produced?

I tried mess about with IUpdateEntityRequestBuilder but could not work it out.

The main reason I have three requests below but first two fail if does not exist as field does not exist. wish to debug but can't see if something I'm doing or if there would be another way i could be make the fluent api to produce different request with SET / ADD, But at moment, don't know how see what my changes make will effect it.

UpdateItem()
.WithPrimaryKey(inventoryItem.PartitionKey,inventoryItem.SortKey)
.On(x => x.Quantity).Increment(inventoryItem.Quantity)

UpdateItem()
.WithPrimaryKey(inventoryItem.PartitionKey,inventoryItem.SortKey)
.On(x => x.Quantity).AssignSum(x => x.Quantity, inventoryItem.Quantity)

UpdateItem()
.WithPrimaryKey(inventoryItem.PartitionKey,inventoryItem.SortKey)
.On(x => x.Quantity).Assign(x => x.Quantity, inventoryItem.Quantity)
.WithReturnValues(ReturnValues.AllNew)





@firenero
Copy link
Contributor

Currently, there is no way to view the actual DynamoDB expression being generated. This feature has been on our agenda since the start, but implementing it is challenging due to some performance-oriented design choices we made.

Regarding the failure of the first two requests due to non-existent fields, you should consider using fallback values. These values get translated into the if_not_exists() DynamoDB function behind the scenes. The high-level API of EfficientDynamoDb provides overloads that employ this function:

var defaultQuantity = 0;
UpdateItem()
.WithPrimaryKey(inventoryItem.PartitionKey,inventoryItem.SortKey)
.On(x => x.Quantity).Increment(defaultQuantity, inventoryItem.Quantity)

UpdateItem()
.WithPrimaryKey(inventoryItem.PartitionKey,inventoryItem.SortKey)
.On(x => x.Quantity).AssignSum(x => x.Quantity, defaultQuantity, inventoryItem.Quantity)

In this example, I've added the defaultQuantity parameter (you can pass 0 or any other default directly without creating a variable).

Generally, if an operation relies on a value already stored in DynamoDB, it's recommended to provide a fallback value to avoid failure. For such situations, seek overloads with fallbackValue parameters (these can have left/right prefixes if there are two operands to the operation).

@firenero firenero added enhancement New feature or request question Further information is requested labels May 27, 2023
@firenero firenero self-assigned this May 27, 2023
@TheBreadGuy
Copy link
Author

thank you for response. worked perfect. sorry should've split into two posts for anyone searching for same thing.

Did know could do that, to get "if_not_exists()"

One reasons wishing to knowing expression being generated, was unsure on which SET or ADD. was being used backend. I assume it is SET. as using second solution from this stackoverflow question . I never thought about asking if I can force selection. with something, like .BySET .ByADD. eg .On(x => x.Quantity).Increment(inventoryItem.Quantity).ByADD

Though I have no need for it myself as can use "if_not_exists()." and I don't think ADD has many other uses.

At first I thought AssignSum and Increment one did SET and other ADD but assume they both do same from reading #100

For that feature on expression being generated could make for non production only (as 90% would only use for debug I think? ) or even standalone one that just output expression ? ( btw , not asking for or needing either, just ideas. I have not much clue on working. did look but to deep for me hah)

=

@firenero
Copy link
Contributor

Indeed, the operation uses SET for addition. I'm not sure why the StackOverflow answer suggests ADD as the preferred method when the AWS documentation, linked in that answer, advises using SET over ADD in general: In general, we recommend using SET rather than ADD.

I don't think ADD has many other uses.

You're right. There are no specific uses for updating numbers that are possible with ADD but not with SET.

At first I thought AssignSum and Increment one did SET and other ADD but assume they both do same

Correct, Increment is essentially a convenient wrapper around AssignSum.

As for generating a debug-only output, this would indeed be a beneficial feature. However, it's a challenge to adapt our existing code to accommodate this function without impacting the performance of production use cases. Ensuring the code remains consistent between production and debug outputs is essential, which adds to the complexity of this task.

At the moment, I can't commit to a timeline as to when we could look into adding this feature. However, we're very open to contributions, so if you or someone else wants to give it a shot and submit a pull request, we'd be more than happy to review it.

@TheBreadGuy
Copy link
Author

Perfect ty. and sorry my code way to messy to consider it lol

@diopolgg
Copy link

diopolgg commented Dec 8, 2023

One way of hooking up to generated request details is by setting the custom HttpClientFactory that returns the HttpClient that accesses the request content (say in DelegatingHandler).

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

No branches or pull requests

3 participants