sql

All things SQL and JDBC...
teodorlu 2020-04-05T14:50:42.153400Z

Really liking the ResultBuilder design and its docs!

👍 1
🦜 3
seancorfield 2020-04-05T17:26:57.153900Z

Glad to hear that! Thank you!

seancorfield 2020-04-05T18:47:08.157300Z

@serioga The with-transaction (and with-db-transction) syntax is meant to be a binding -- like any standard binding in Cojure, that folks are used to using. In real-world code that I've (over nearly nine years of maintaining Clojure wrappers for JDBC, it's pretty common to have

(jdbc/with-transaction [tx (some-expression)]
  ,,, tx ,,,)
and less common to see
(jdbc/with-transaction [tx sym]
  ,,, tx ,,,)

seancorfield 2020-04-05T18:50:10.160200Z

I'll admit that I made a mistake, syntax-wise, by allowing an options map as an optional third element in that binding. I've always regretted that (and I've often tried to think of ways to add a new, better syntax while deprecating the current third expression version, but keeping it around for backward compatibility).

serioga 2020-04-05T18:50:27.160500Z

I feel like jdbc/with-transaction [tx (some-expression)] does not fit well when (some-expression) return connection and not datasource

seancorfield 2020-04-05T18:51:39.160900Z

I don't understand what you mean by that.

seancorfield 2020-04-05T18:52:40.162100Z

It can be anything that with-transaction can get a connection from, on which to build the transaction. That's the same as execute!, execute-one!, and plan

serioga 2020-04-05T18:53:21.163Z

the code

(jdbc/with-transaction [tx (get-connection)]
  ,,, tx ,,,)
requires me to care about closing got connection which is not an issue when you work with datasource

seancorfield 2020-04-05T18:54:21.164Z

No, you don't need to worry about that. It's automatic.

serioga 2020-04-05T18:54:53.164800Z

so when with-transaction works with datasource — everything works automatic when I work with connections, I need to wrap it with with-open and so on

seancorfield 2020-04-05T18:55:01.165100Z

It's exactly the same as how execute!, execute-one!, and plan work.

seancorfield 2020-04-05T18:55:59.165900Z

Oh... I see what you mean now... Yeah. But you can just pass a db-spec or a datasource, if you don't want to manage the connection.

serioga 2020-04-05T18:56:35.166400Z

it did not work in my tests and this is obvious because with-transaction can't know if connection can be closed at the end (because connection was provided outside)

seancorfield 2020-04-05T18:56:49.166800Z

But you can also hand it an existing connection and it will build the tx on top of it and then restore the connection.

seancorfield 2020-04-05T18:57:09.166900Z

See my response in the main channel.

seancorfield 2020-04-05T18:58:28.168200Z

But it's exactly like any other binding expression in Clojure. It's what people expect.

serioga 2020-04-05T19:00:16.169800Z

> But you can just pass a db-spec or a datasource, if you don't want to manage the connection. but I want. in most places I work with connections, and only in some places with transactions and I prefer to keep datasource hidden

seancorfield 2020-04-05T19:02:33.172Z

OK, but I think you're fighting against the design of the library -- the docs emphasize making a DataSource (from a hash map or string, mostly) and using the datasource "everywhere". Both java.jdbc and next.jdbc work the same way -- the latter just tries harder to encourage that approach.

serioga 2020-04-05T19:03:10.172100Z

I'm totally fine with my wrapper around your macros

serioga 2020-04-05T19:03:48.172900Z

I'm not fighting, you are the author and you answered on my question in the past

serioga 2020-04-05T19:04:40.173900Z

I just mentioned that chosen design leaded to errors found today by linter.

seancorfield 2020-04-05T19:08:20.176400Z

It's just the "same" error as using the wrong variable anywhere in Clojure (and I've found the exact same error in other Clojure code that's not using JDBC).

serioga 2020-04-05T19:08:23.176500Z

Generally my question in the past was initiated by previous using of http://funcool.github.io/clojure.jdbc/latest/api/jdbc.core.html#var-atomic which was fine for me to use

serioga 2020-04-05T19:10:45.178300Z

> It's just the "same" error Usually using wrong variable leads to non-working code. In this case both vars are almost the same, so everything works instead of transactional processing, what really hard to mention 🙂