Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add a way to reset queries so they can be reused #745
Conversation
Also add a flag that generates models that resets the query after each finisher.
|
Can I get some feedback on this PR? |
|
Hello @stephenafamo, and thanks for the PR! Apologies for letting this sit for so long. This PR doesn't work for the reason I highlighted, but I'm also not sure if I'm willing to accept such a syntactically noisy addition. It does solve the problem, but it requires so much additional "stuff" in order to reset a query that it doesn't seem worth it. Ideally we'd be able to have queries just magically resettable (if there is such a way) and I'd like to prove that that's not possible before pursuing a route like this. |
|
|
||
| // Save removes the effect of a finisher | ||
| func (q *QueryReset) Save() { | ||
| q.saved = *q.q |
aarondl
Jun 17, 2020
Member
This is insufficient because it does not do a deep copy. If slices/maps are modified in the query it could affect a saved query.
This is insufficient because it does not do a deep copy. If slices/maps are modified in the query it could affect a saved query.
|
Thanks for the feedback. I could make some changes to the PR, but I think it's better if I get a better sense of how you'd prefer the reset to work. I think this feature is useful, but I'd like to understand what you have in mind so I see if it is something I can work on. |
|
My issue with the approach lies in the fact that users will not try that first. They'll first try what andradei tried:
And only after they encounter errors/problems will they seek a resolution and finally find the resetter and learn how that works and use it. Perhaps that's better than "they encounter errors/problems and seek a solution only to find one doesn't exist" but does there exist a design where we could simply have the obvious thing work without any additional syntax? Basically what I'd like to happen (whether or not it's possible is another question) is for andadei's example to function as he expected it would. I haven't been in the code in-depth for a very long time so I actually do not know if that's possible or what we would have to give up in order to have it (for example query caching inside the query object maybe) so that investigation would have to be done before we could make a decision. |
|
Okay. I'll do some research on this later, and see if I can think of a clean way to implement this. |
Also add a flag that generates models that resets the query after each finisher.
Fixes #647
When the models are generated with the flag
--add-reset, Queries started withmodels.Pilot()can be reused. For example:Previously that will throw an error.
It also adds the type
QueryResetwhich is the primary way or resetting queries. For example:This method is also completely backward compatible.