Fork me on GitHub
#hugsql
<
2022-04-14
>
JB Seo01:04:24

Hello, I have a question on the latest release v0.5.2. ā€¢ fix fn defs to be at compile-time https://github.com/layerware/hugsql/issues/126 (thanks https://github.com/kelvinqian00https://github.com/kelvinqian00)!) Does it work well with leiningen? With leinignen, uberjar with option 'aot all & omit-source' still throws 'Can not read file' exception. Test project: https://github.com/jngbng/hugsql_aot

JB Seo01:04:07

Honestly, I don't understand why switching 'def-db-fns' from macro to a normal function would prevent executing it on runtime (so that it will not read SQL file on start up.)

seancorfield02:04:14

@jbseo The assumption is that you are calling (def-db-fns) as a top-level form in your namespace so when you load the ns (for compilation) it runs and loads the SQL and defines all the functions. If you're calling (def-db-fns) anywhere, it's not going to work.

seancorfield02:04:25

(at least, that's my reading of the changes made in 0.5.2)

JB Seo02:04:42

With the following file:

(ns hello.echo)

(prn "I am hello.echo")
I will see the greeting message both on AOT compilation time and on starting the program. Am I right?

seancorfield02:04:25

I'm just guessing at their intent: I'm not saying it actually works if the source is not present in the JAR file šŸ™‚ I don't know how well it has been tested...

JB Seo02:04:13

I see, Thanks!

seancorfield02:04:45

In #126, the OP says "Indeed it does work! (Plus the conversion from using macros to regular functions cleans up the core code.)" so the solution worked for their use case...

seancorfield02:04:20

(that convo suggests it does work for them since they are excluding .sql files from their JAR...)

JB Seo02:04:40

Yes, so I wonder how it could be possible. With the definition of https://github.com/layerware/hugsql/blob/ad73d080f84487c3438058ed5203d44f06c46365/hugsql-core/src/hugsql/core.clj#L530, I think it should read SQL file on start up time.

seancorfield02:04:11

I just tried it with your repro project and even with a few tweaks and edits, I cannot get it to work "as advertised" so it definitely "doesn't work" as I would expect.

seancorfield02:04:57

You could create a new issue and link back to #126 and your repo.

curtis.summers12:04:52

Yes, this is still not working (even with depstar as in the original issue). I've updated that bug, and will try to get a fix out in the next few days. I'll probably switch back to macros.

seancorfield21:04:39

It's a tricky one -- and macros vs functions is irrelevant I think since the issue is about invocation at load time which happens for both compilation and for running in a standalone JAR.