What I'd like to do is if there is :schema
parameter is given, then tables in my SQL need to get "myschema.table", but if that parameter is absent, then it's just "table"
And I can't find a sensible way to do that in hugsql
@roklenarcic A few options for you: 1) HugSQL identifier parameters support "schema.table" notation: https://www.hugsql.org/#param-identifier (see toward the bottom of this section). That, of course, would require you to pass your table names in as parameters. 2) You can use a Clojure Expression (https://www.hugsql.org/#using-expressions) to check for the existence of the :schema
parameter and modify your table names accordingly. 3) The non-HugSQL specific might be to "SET SCHEMA" or "SET search_path" (postgres) on your queries.
On 2, the Clojure Expression might look something like: from /*~ (if (:schema params) (str (:schema params) ".mytable")) "mytable") ~*/
(untested; also if you're taking :schema
from user input, you'll need to escape/quote it appropriately...see the usage of identifier-param-quote
in the docs under Clojure Expressions)
the thing is that I tried the Clojure Expression route, but it was very verbose
which is why I wondered if it might be solved with snippets
can't use set schema as I'm using two schemas simultaneously
it would be really helpful if snippets could be parameterized at use site