Feat: Adds SelectStatement::apply
method for functionally building query in another function
#730
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Heya! 👋 Thanks for all your work on the library- I've really enjoyed working with it! I ran into a quality of life shortcoming with the API around the
SelectStatement
builder: I wanted a clean way of building a portion of the query in another function, similar to the pattern used by theconditions
method, but without the actual conditional part 😁PR Info
New Features
Added
apply
method toSelectStatement
for constructing part of the statement from another functionThis new method is essentially a shorthand form of using the
conditions
function with a hardcoded value:This is useful in cases where multiple queries have the same "core" expressions, like when gathering results vs counting total query size (for pagination) on a query with joins, conditional where clauses, and groupings:
This is somewhat contrived example to keep it as simple as possible. For my use case, the function used to build common expressions on the query is a struct method that's referencing it's own internal state to apply the conditional filters:
Bug Fixes
None
Breaking Changes
None
Changes
None as of initial authorship, however the
SelectStatement::conditions
method could be updated to call out to the newapply
function if so desired, but it'd be a little pedantic: