Use a MYSQL variable as argument in JS function (in a single query)

Is it possible to set a user-defined variable in a MYSQL query, and then in that same query, call a javascript function, using that variable as an argument?

Here is an example of what I am trying to do. Calling the variable as an argument doesn’t work, I am guessing because it is meaningless inside of the {{}}.

SELECT @media_id := MAX(id) from media;
INSERT INTO categories (media_id, category_id)
  VALUES {{functions.prepare_values_statement(@media_id)}}; 

@trebuchet in this case, what you can do is to create 2 separate queries. i.e 1 to fetch the max id from media and then one to insert the values and using JS pass the values from fetchMaxMediaId to insertCategory

Ok, thanks @Nikhil . I will end up doing this.