sql

All things SQL and JDBC...
JohnJ 2021-01-27T04:05:38.020900Z

Hello, does next.jdbc has something built-in to leave out from the result set map entries with nil values?

seancorfield 2021-01-27T04:13:17.021800Z

It's mentioned in the Result Set Builders section of the documentation https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/doc/getting-started/result-set-builders#nextjdbcoptional

JohnJ 2021-01-27T04:17:16.022300Z

aha my bad, thank you

JohnJ 2021-01-27T04:23:18.022700Z

you though of all the good stuff, great lib

seancorfield 2021-01-27T04:32:34.023800Z

Thanks. I expected to use the optional stuff a lot more than I have. But we have a large legacy code base and still have to preserve nil in that, even where we're switching from clojure.java.jdbc to next.jdbc...

JohnJ 2021-01-27T16:20:16.025100Z

Have those nils cause any trouble? would you say you are better off without them?

seancorfield 2021-01-27T18:06:42.026100Z

@jjaws I'm not sure how that relates to the optional null issue -- can you elaborate?

seancorfield 2021-01-27T18:09:04.028Z

If you do a join in next.jdbc, the columns are qualified with the table name (by default) so you get (the equivalent of) {:users/uid 1, :sessions/uid nil, ...} and if you decide to use the "optional" builders then :sessions/uid would be omitted -- because it is null, not because it overlaps.

seancorfield 2021-01-27T18:09:44.028800Z

(if you use unqualified map builders, you get collisions and last-one-wins -- which is documented and that's why the (default) qualified builders are recommended)

JohnJ 2021-01-27T19:43:14.030Z

@seancorfield yeah, was just shock that the node client doesn't have this feature

JohnJ 2021-01-27T19:43:58.030300Z

was unrelated to the null issue

seancorfield 2021-01-27T20:11:22.032300Z

clojure.java.jdbc had logic for making columns unique, but the problem with that was you couldn't tell which of uid, uid_1, uid_2, etc came from which tables. next.jdbc just punts on the issue completely: if you use table-qualification, it's "solved" unless you're joining a table to itself (also mentioned in the docs -- you have to explicitly alias the joined column to disambiguate).

JohnJ 2021-01-27T21:41:05.035400Z

yep, using as all over the place with the nodejs client was tedious, next.jdbc does the right ergonomic thing.

JohnJ 2021-01-27T21:43:09.037Z

my original unrelated question was more about the use of nil in maps in your legacy code base, has it cause any frustrating issues?

seancorfield 2021-01-27T21:49:05.038900Z

"legacy code base" is complicated in our case. Our legacy apps are not all Clojure, so the hash maps from clojure.java.jdbc (and now next.jdbc) get handed back to non-Clojure code where is-the-key-present? and is-the-key-value-null? are substantially different questions so preserving nil-valued keys is important, unfortunately.

seancorfield 2021-01-27T21:50:12.040200Z

If I were starting over with pure Clojure code that was not going to be reused by non-Clojure code, I would likely be more aggressive about using the optional builders and having a codebase where "absence" was the decider rather than "nullable".

JohnJ 2021-01-27T21:59:08.040400Z

got it, was just curious about nil in maps in practice

seancorfield 2021-01-27T22:00:45.040800Z

https://corfield.org/blog/2018/12/06/null-nilable-optionality/ talks about it.

👀 2