SQL Formatter library is not visible, how do I get it work?

I'm trying to format some sql statements, so I needed a library to do that. I've added the following library to retool, https://cdnjs.cloudflare.com/ajax/libs/sql-formatter/4.0.2/sql-formatter.min.js, however the format function from the library is not visible in either js queries or inside {{ }}. Any idea how to make that work?

I tried using an external library last week. At least for me, the function didn't autocomplete or pop up as I was writing code, but when I wrote the function and saved it, and ran the query, it executed just fine. I also had to refresh the page for it to load properly. Maybe this helps?

it unfortunately doesn't work for me

You're going to have to provide a reference to the package name when you do use it, and it turns out that that hyphen is problematic. I can't figure out how to get around it with quotes or backticks. Someone who knows more javascript will need to figure out the best way to reference it.


Try sqlFormatter. I'm not exactly sure how retool names imported libraries, but in this case it converts kabob case to camel case.

I found this by adding the library and then creating a JS transformer to search global names for "sql":

return Object.keys(window).filter(a => a.match("sql"));
1 Like

yeah sqlFormatter works! thanks for showing me how to search for global vars as well :slight_smile:


Glad you got it!

Thinking a bit, for locating imported libraries, a case-insensitive search would work in more situations, like:

return Object.keys(window).filter(a => a.match(/formatter/i));