sql

Andrey Subbotin 2023-12-01T20:40:02.036259Z

This is probably something trivial, but I can't seemingly find an answer to this. I'm using next.jdbc to access my sqlite DB. I use HoneySQL to generate SQL statements to execute. My DB tables and their columns are named in snake_case. Yet my Clojure code operates on :dash-separated-keywords. Is there a way to make next.jdbc/HoneySQL convert between the two name schemes automatically for each query and each result set?

seancorfield 2023-12-01T20:42:47.007919Z

Can you be a bit more specific about what exactly you're doing? HoneySQL will turn :a-b into a_b:

user=> (sql/format '{select (a-b, c-d) from t-1 where (= a-b.x-y 42)})
["SELECT a_b, c_d FROM t_1 WHERE a_b.x_y = ?" 42]
so I imagine you're looking to turn a_b in the result set back into :a-b?

Andrey Subbotin 2023-12-01T20:43:49.405489Z

Yep, that's right.

seancorfield 2023-12-01T20:44:23.700919Z

I actually prefer having the DB results match the DB table/columns so I can see that this is raw data from the DB but the next.jdbc docs explain how to get kebab-case back -- Getting Started: https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.894/doc/getting-started#options--result-set-builders

➕ 1
seancorfield 2023-12-01T20:44:43.078999Z

(there's a lot of information in the Getting Started guide you will find useful)

seancorfield 2023-12-01T20:45:43.905459Z

Also described in the API docs: https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.894/api/next.jdbc#snake-kebab-opts

Andrey Subbotin 2023-12-01T20:48:03.397769Z

Thanks heaps! This seems to be exactly what I was looking for. How did I miss this? 😓 😇

seancorfield 2023-12-01T20:48:53.681699Z

A lot of folks read the docs bit seem to miss all sorts of "gems" -- I'd be happy to improve the docs if you have suggestions!