Extending SQL macros

I’m trying to get a dataset working with grafana with multi-variables input, but there I’m limited by complexity of my SQL query. Is there a way to extend the macro’s like $__timeGroup() to build SQL in a javascript file?