clj-kondo

dazld 2025-08-01T11:00:58.534269Z

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?

❌ 1
dazld 2025-08-01T11:27:43.955299Z

Reading a bit more, this is by design? I’ll park this for now and look at other ideas.

2025-08-01T11:35:21.005849Z

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

👍 1
dazld 2025-08-01T11:39:04.341959Z

preprocessing does seem like the way forward here.

dazld 2025-08-01T11:39:22.694819Z

a manifest of some sort as plain data…

2025-08-01T12:00:31.829029Z

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

👍 1
DrLjótsson 2025-08-02T12:41:10.848669Z

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?

👍 1