Comment by tracker1
I've either imported or created a sql template function that does exactly that... takes the parameters, forms a parameterized query against the database and returns the results back. Easy enough to add Typescript types that should match your expected results (though not enforced/checked) still helpful.
I know. My point was that the original text of the article gave no explanation next to that example as to how $ executes given string. So either there is some magic or the example was wrong. Author added explanation after my comment