kit icon indicating copy to clipboard operation
kit copied to clipboard

Cannot access HugSQL snippets by name

Open pyiso80 opened this issue 9 months ago • 1 comments

I was expecting I would be able to use HugSQL snippets via query-fn. But it seems I can't. I have the following:

-- :snip select-snip
select :i*:cols

-- :snip from-snip
from :i*:tables

-- :name snip-query
-- :result many
:snip:select
:snip:from

And I tried something like this:

;; slect-snip and from-snip are not detected.
(def query-fn (:db.sql/query-fn state/system))
(query-fn
  :snip-query
  {:select (select-snip {:cols ["id","first"]})
   :from (from-snip {:tables ["contact"]})})

And I got the following error:

Execution error (IllegalArgumentException) at conman.core/find-fn (core.clj:115).
no snippet found for the key: :select-snip', available queries: 

(Note: if I load the query file like by running (hugsql/def-db-fns "sql/queries.sql"), the above works because snippets becomes available in the namespace.)

It seems, with query-fn, only the normal query functions are available, but not the snippets. For constructing SQL dynamically, should I consider other alternatives such as HoneySQL?

pyiso80 avatar Mar 13 '25 15:03 pyiso80