Fork me on GitHub
#sql
<
2018-05-11
>
grav11:05:29

@seancorfield You’re probably right that I miss-read the docs. I did use with-db-connection, but in my scenario, the connection is sometimes lost, and I’m not sure the macro handles this, right?

grav11:05:45

Anyway, a way for me to deal with this is to have an atom with a connection, and then once in a while make a new connection if the old fails.

grav11:05:46

If you or anyone else know a better strategy for this kind of resilience, I’d be very happy to know 🙂

seancorfield17:05:07

@grav Using an atom for the connection sounds like a terrible hack to me. with-db-connection will open the connection, run the body of the form, and then close the connection. It shouldn't get "sometimes lost" unless you have a flaky database or a flaky network?

seancorfield17:05:05

I'd recommend reading the docs for Reusing Connections and considering a connection pool (we use c3p0 heavily at work, I've heard other folks praise Hikari, and there are a few other options).

seancorfield17:05:13

If you use a connection pooling library, bad connections should automatically be dropped and new connections created. But if connections are going bad (due to network/DB issues) you would have to decide whether to retry a given (set of) SQL operation(s). That's true regardless, since "the network is broken", and applications all need to build in resilience somehow for failures of any external interactions.