This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-05
Channels
- # aleph (2)
- # announcements (3)
- # architecture (5)
- # beginners (51)
- # biff (5)
- # cider (1)
- # clerk (8)
- # clj-kondo (6)
- # cljsrn (5)
- # clojure (31)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (3)
- # emacs (11)
- # fulcro (2)
- # graphql (6)
- # hugsql (1)
- # jobs (2)
- # leiningen (3)
- # lsp (3)
- # malli (13)
- # missionary (1)
- # off-topic (7)
- # pathom (7)
- # polylith (27)
- # reagent (14)
- # reitit (3)
- # remote-jobs (7)
- # shadow-cljs (20)
- # spacemacs (4)
- # sql (3)
- # tools-build (4)
- # xtdb (7)
hi, what is the best practice in using HugSQL with polylith? how should I export DB functions generated by polylith via interface? Do I need to export them manually or is there a better way
I haven’t worked with HugSQL myself, but one way of exposing functions and data is to put it in a sub namespace in the interface, e.g. my.top.ns.mycomponentinterface.interface.sql
.
the issue I am asking is more about how to export the fn's? hugsql generates vars at runtime by loading and SQL file and creating a fn for every query: Doing the bellow calls will add fn's to the current namespaces.
(hugsql/def-db-fns "dre/app/db/articles/core.sql")
(hugsql/def-sqlvec-fns "dre/app/db/articles/core.sql")
(hugsql/def-sqlvec-fns "dre/app/db/articles/articles_for.sql")
But once these statements have been executed, HugSQL can then do its magic?
not sure I understand. let me give more info, maybe we can find a solution.
so for example, articles/core.sql
contains:
-- :name do-truncate-articles! :!
truncate articles;
after the call to
(hugsql/def-db-fns "dre/app/db/articles/core.sql")
the ns will contain a fn (not in file, at runtime) that has the name do-truncate-articles
.
I can cal do-truncate-articles
and pass it a SqlConnection / DataSource and it will truncate the articles table.But would’t you have to do that even without Polylith?
Why do you think you have to do more work with Polylith? What is the difference?
Because you need to access them from other components?
But then using a sub interface can be a good idea, having them in one place.
Yes, and that is allowed. It can be the best choice in some situations if you have one-liners or tiny functions.
Delegating to an implementing namespace is just best practice, in most cases.
thanks for the dicsussion. It really helped clear tings up. I did not find any info about this topic so hopefully now there is some
Okay, cool. If you have more questions later, don’t hesitate to ask.
Sonds like a good idea! 🙂