Cannot access HugSQL snippets by name
- Dominant language
- Clojure
- Stars
- 558
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at conman.core/find-fn in core.clj:115 and compare the query-fn path with loading the SQL file through hugsql/def-db-fns, using the provided :snip-query example as the reproduction. Trace how named snippets are registered and define done as either resolving select-snip and from-snip through query-fn or documenting the supported limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100