Fork me on GitHub
#sql
<
2020-06-20
>
adam20:06:47

Is it possible to set :table-fn option globally in next.jdbc? Or I have to wrap all the Friendly SQL Functions for that?

adam20:06:50

(trying to use update! on a table called user)

seancorfield21:06:43

What I do at work is to have a def at the top of my SQL namespace that has the default options I want in any/all next.jdbc calls and just pass that as the last argument in each call.

seancorfield21:06:17

Because next.jdbc traffics in pure JDBC (Java) objects, there's no way to provide "global options" @somedude314

seancorfield21:06:43

But I am working on a middleware/wrapper approach that would allow you to create something "connectable" that could carry additional options. It's tricky because it has to be done in a way that causes no overhead for folks not using it, and that it composes in reasonable ways.

adam21:06:44

Gotcha, I think I am just gonna wrap it for now. It's an opportunity to avoid passing connectable for the already non-pure function

seancorfield21:06:43

Ah, you're already relying on the connectable as global state rather than passing it through the call chain?

seancorfield21:06:10

(I would advise against that since it makes code harder to test and also ties you into a single datasource)

adam22:06:11

I was injecting it into the Ring's request object via a middleware then my handler was passing it to the hugsql/next.jdbc functions. I thought it would make my code simpler if I make the data source and next.jdbc options for insert!, update! optional

adam22:06:28

But I can see how that will make my handlers harder to test, won't do it. Thanks for the advice 🙂

seancorfield22:06:41

Passing it through the Ring request is fine because it's an argument everywhere.

seancorfield22:06:01

I thought you meant you had it as a global in the namespace where you were wrapping the next.jdbc calls.

adam23:06:20

Yep. Sorry for the confusion. I was doing the middleware approach then contemplated dropping it above. I will stick with it.