Fork me on GitHub
#sql
<
2022-04-11
>
Marius14:04:12

Hi all! I was wondering if using a result (perhaps just a fixed value?) from a (jdbc/with-transaction ...) block (which does some inserts) is a sufficient check whether the transaction was executed successfully? Like anything other than an exception is a success… Or is there a better way to conditionally run business logic after a transaction?

bortexz21:04:01

If I have a keyword value on clojure, what would be the way to store that in sql? how about reading it back to a keyword (namespaced) in next.jdbc?

bortexz21:04:32

or is it a better practice to already have those values as strings in clojure?

Cora (she/her)21:04:53

you'd need to convert it to edn

bortexz21:04:22

not sure I follow, what would be the type I would use in e.g. Postgresql? I was thinking string so that I can do indexing etc, you mean converting it manually on writing/reading?

bortexz21:04:15

I was wondering if there was a way to automatically convert a given column , but I guess doing the conversion when reading/writing does also work

Cora (she/her)21:04:20

that will convert to/from json for you. I'm sure there's a way to like make a custom type in postgres and add automatic conversion with edn but really that seems like a huge pain

bortexz21:04:20

I was thinking on primite type colums (a string in DB that is a keyword on clojure, or enum in pg maybe?), but I’ll also need that for json/edn interop, thanks

bortexz21:04:22

hmm enums like described here might be what I was looking for: https://www.bevuta.com/en/blog/using-postgresql-enums-in-clojure/

Cora (she/her)21:04:13

that jdbc/IResultSetReadColumn looks like it could potentially cause some issues

Cora (she/her)21:04:52

if any other string column gets one of the enum values it would automatically convert that, too

Cora (she/her)21:04:35

also that looks like it's using the old version of jdbc for clojure

Cora (she/her)21:04:09

specifically clojure.java.jdbc instead of the newer next.jdbc

Cora (she/her)21:04:05

I'd just accept that it's going to be a string, myself

bortexz21:04:34

yes you’re right, I think I’d change the implementation, though going for enums might be a reasonable approach (as the kw values I was thinking of are specced as sets of possible values in clojure)

bortexz21:04:26

the easier way seems to be to transform directly on clojure and have it as string

bortexz21:04:19

I’ll investigate a bit more but it looks like the solution will come from one of those two approaches

bortexz21:04:23

thanks for the help!

Cora (she/her)21:04:50

👍:skin-tone-2: