Closed csansoon closed 3 weeks ago
Latest commit: d33e41c54202a0ae50e493a184e5617fe94e2e3b
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Since now we can do some things like {results[0]?.name ?? 'default'}
, I was thinking we could also do something like {param('start_date')?.getYear()}
. This would mean changing the param
function where, if the parameter does not exist, it should return undefined
instead of raising an error. What do you think? Would it be better to crash, or just return undefined?
In the case of SELECT * FROM user WHERE id = {param('user_id')}
, if no user is given that would not fail, but just return an unexpected response. I don't know what's better for the user in this case.
Thoughts?
I agree on supporting object properties on param() calls but I don't understand why it means we need to allow param returning undefined.
Describe your changes
Compiler did not properly handle object properties. Before this commit, you could not:
?.
)Invoke object properties as methods
Some variable types can contain functions that may be useful in the query compilation run-time. A clear example is Dates, where a Date can be passed to a query as a param, and we may want to run date-related methods.
Modify object properties as methods
You can now also modify the value from object properties such as arrays and hashes.
Allow optional chaining operator (
?.
)The optional chaining operator allows you to read the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid.
Checklist before requesting a review