PROPOSAL: Allow custom placeholders/functions in @Formula annotations #2416
jonasPoehler
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are currently faced with the problem that we would like to have more flexibilities with the @formula annotations. Since these are annotations, you are very limited in what one can do with them, since they are basically final at compile time.
There already is a rudimentary option to use placeholders in
@Formula
and@Where
annotations like${ta}
which is replaced by the table alias. A regular usecase for us would be a today-function, which can be used to calculate something like how many days overdue is a task. Since a today-function in a user-facing application is always dependent on the timezone the user is in, this cannot be done statically on an annotation. Another use-case of the same principal would be time to date or date to time convertions using the user's timezone.Additionally you could use something like this to define common functions to resolve database specific operations like bit-operations instead of having one
@Formula
-annotation per database system for one small difference in actual sql. This could help to make the code less verbose.Examples of how the annotations could look like in the models:
A possibility to implement this, is to allow to set this on the
DatabasePlatform
, when configuring the database server.The definition of the functions for different database platforms then could look something like this:
In theory this should not add too much complexity, but would allow some nice extensions to help with code readability and maintainability. If this would prove popular I would try and implement this and open a Pull-Request, but I'm also open to suggestions or different ideas in this regards.
Beta Was this translation helpful? Give feedback.
All reactions