Fork me on GitHub
#sql
<
2023-12-01
>
Andrey Subbotin20:12:02

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?

seancorfield20:12:47

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 Subbotin20:12:49

Yep, that's right.

seancorfield20:12:23

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
seancorfield20:12:43

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

Andrey Subbotin20:12:03

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

seancorfield20:12:53

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!