EJS is a java code generator. You can import any existing java library and use it with EJS.
So if you include java library for mysql , you will be able to execute sql statement with function call and do what you want.
I know that it can be done. But I have never try it. So I do not have example to share with you.
I think this in-direct method will be easier to implement.