hugsql

roklenarcic 2018-08-20T09:04:45.000100Z

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"

roklenarcic 2018-08-20T09:05:04.000100Z

And I can't find a sensible way to do that in hugsql

curtis.summers 2018-08-20T12:51:16.000100Z

@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.

curtis.summers 2018-08-20T12:57:01.000100Z

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)

roklenarcic 2018-08-20T13:17:14.000100Z

the thing is that I tried the Clojure Expression route, but it was very verbose

roklenarcic 2018-08-20T13:17:37.000100Z

which is why I wondered if it might be solved with snippets

roklenarcic 2018-08-20T13:18:14.000100Z

can't use set schema as I'm using two schemas simultaneously

roklenarcic 2018-08-20T13:35:17.000100Z

it would be really helpful if snippets could be parameterized at use site