Is it possible to pass an entire record as a parameter to a function, similarly to Postgres, in MySQL 8? If not, are there any alternatives?
The specific use cases are:
- Define custom (record -> bool) filters to be reused in multiple queries
- Define custom mappings (record -> JSON)
For the first use case (custom filters) an example would be converting a row of a table appointment
:
id, user_id, begins_at, ends_at, is_something, cancelled_at
into this expression:
(
is_something && (cancelled_at IS NULL && @someDate > begins_at && @someDate < ends_at)
|| !is_something && (@someDate > ends_at)
)
so that I can reuse this expression.
For the second use case the idea is given the same appointment
to convert it into a specific JSON shape (MySQL 8) with subqueries and nested objects.