Skip to content

Cannot access HugSQL snippets by name #160

@pyiso80

Description

@pyiso80

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions