Fork me on GitHub
#sql
<
2020-11-16
>
dharrigan15:11:19

@seancorfield In next.jdbc, you now have the as-*-snake-kebab if the csk library is on the path. Would you consider also adding as-*-camel-case? The rationale is that it's very common when interfacing with external consumers to send to them JSON (i.e., javascript frontends). Thus, having the ability to simply do, for example {:builder-fn rs/as-unqualified-camel-case-maps}) would help tremendously, rather than having to do something like this:

dharrigan15:11:20

(defn camel-case
  [rs opts]
  (let [camelCase #(->camelCase %)]
    (result-set/as-unqualified-modified-maps rs (assoc opts :qualifier-fn camelCase :label-fn camelCase))))

dharrigan15:11:29

I can raise an issue if it helps 🙂

dharrigan15:11:18

(Or, I was looking at the code on the v1 branch, and I could copy pasta the defmacro for def-snake-kebab [] in the result_set.clj)

seancorfield18:11:07

I won't accept a PR for that: snake_case is much more common than camelCase (in both the DB tables/columns and in external JSON systems) and it's easy enough to write a builder to produce camelCase based on the existing adapters -- you could stick that function above in a common ns in your code and easily reuse it everywhere. Another argument against this is that it is fairly unlikely that an external system is going to just magically match your DB naming so an automatic conversion won't help you (and tying your DB structure directly to that external system's current naming convention is a Bad Idea(™) anyway).

dharrigan18:11:31

Oooh, that's not the case Sean

dharrigan19:11:36

I don't know which systems you work with, but in my experience, camelCase for JSON is a lot more common. I rarely see JSON of this form "foo_bar", more like "fooBar"

dharrigan19:11:59

but no matter. I do use already the function as I have shown above.

seancorfield19:11:47

Fair enough. Either way, I only baked in snake/kebab because I kept seeing people reinvent it in buggy ways -- I still sort of regret it, since it's easy enough for folks to "do it right" with the CSK library. Yours is the first request I've seen for camelCase (ever, as far as I can remember, across all the years of c.j.j and next.jdbc).

dharrigan19:11:23

There's always one, isn't there 🙂

seancorfield20:11:09

And it's always you, isn't it? 🙂

dharrigan20:11:27

someone has to 🙂

Asko Nõmm20:11:38

Hi! I’ve been told to write about my concern here, so I’m reposting this: Does anyone have any experience with jdbc / mysql here? Namely I have an issue where after some time of inactivity, and then again trying to connect to the database .. it fails with a `Operation timed out (Read failed)` . I’ve been trying to find a way to configure it to reconnect on timeout, but haven’t yet found a way. Does anyone have any ideas?

dharrigan20:11:07

Do you use a connection pooler?

dharrigan20:11:23

For example, HikariCP will automatically reestablish timeouts

seancorfield20:11:54

How long is "some time of inactivity"? I seem to recall MySQL's JDBC driver auto-closes inactive connections after some time period (but I think it's hours).

Asko Nõmm20:11:58

It could easily be an hour or so

Asko Nõmm20:11:18

For what it’s worth, I’m using Korma as an ORM. I’m looking into HikariCP tho’!

dharrigan20:11:14

I use HikariCP with PostgreSQL (I have used mysql and mariadb too), and it will keep the connection alive to the db, even when the db goes down, when it comes back up again, it will reestablish the connection. which is neat.

seancorfield20:11:41

Korma is unmaintained and uses a very old clojure.java.jdbc version. I would suggest you reconsider that path. We really don't use ORM-style libraries in Clojure (but, if you must, look at Toucan which is at least still maintained).

dharrigan20:11:34

yeah, agree there. I am sooo thankful of not having to mess around with hibernate or java jpa shenanigans since moving to clojure

Asko Nõmm20:11:31

Excuse my naiveness, I’m new to working in the back-end with Clojure, coming from CLJS. Thankfully my project is new enough to re-work that part rather easily, so I think I’ll just go with Hikari and report back! 🙂

dharrigan20:11:43

saying that, I do also work in Kotlin and I can recommend JOOQ as a very nice abstraction layer (akin to honeysql/nextjdbc on Clojure)

dharrigan20:11:42

If you want to see a stupid little example of using hikaricp and nextjdbc/honeysql (targeting a postgresql database, but it’s so simple, could be mysql/mariadb too), then here you go https://github.com/dharrigan/startrek/blob/master/src/startrek/db.clj

Asko Nõmm20:11:15

Holy moly, that’s awesome! Thank you very much!

dharrigan20:11:31

it’s only a small example, others have examples too, e.g,

dharrigan20:11:14

enjoy! I hope you find not having to worry about ORMs liberating! 🙂 of course, usual cavets apply, YMMV, don’t trust anyone on t’interwebs etc….

seancorfield20:11:27

next.jdbc has built-in support for connection pools with both HikariCP and c3p0 (we use the latter at work in production but most people use HikariCP).

seancorfield20:11:59

We use HoneySQL very heavily in production at work, with a combination of clojure.java.jdbc (in our legacy Clojure code) and next.jdbc in our more recent code.

seancorfield20:11:46

I maintain all three of those. This channel is good for general SQL Qs and also for c.j.j and next.jdbc. There's a #honeysql channel if you want to dig into that library.