I was just playing around with a hook for yesql.core/defqueries - it reads an sql file and creates functions in the namespace it was called that correspond to comments in the sql file, so if we had:
(defqueries "private/sql/bar.sql")
which had content of:
--name: foo
SELECT * from stuff
it would create the function foo
It seemed like it might be straightforward to read the sql file referenced in the defqueries call and do similar parsing.. but I can’t see how to load the sql file.
tl;dr - Is there an API call inside hooks to load an arbitrary file from the classpath?Reading a bit more, this is by design? I’ll park this for now and look at other ideas.
i think what you could do is have a preprocessor that uses rewrite-clj to edit a list of function names in the hook file. you run script/gen-sql-fns, it populates the list in resources/clj.kondo/yesql/etc
preprocessing does seem like the way forward here.
a manifest of some sort as plain data…
you could duplicate some code from yesql to parse the names directly from the sql files. then the files are the single source of truth and you don't need to edit anything, just run the gen script every time you add or change one
I use Calva and my hug sql queries are magically identified. So I guess there is a hook for hug sql somewhere that you can use for inspiration?