sql

All things SQL and JDBC...
Timofey Sitnikov 2021-06-06T01:00:49.098200Z

@seancorfield, as far as the docs I blame my beginner'ish status. But for me, that example makes it super clear, after seeing the example the docs make sense.

seancorfield 2021-06-06T01:13:59.100300Z

OK, cool. I will probably add an explicit example of use.

seancorfield 2021-06-06T01:45:59.102Z

The idiomatic approach for keys with next.jdbc is qualified keywords, per the documentation and the default behavior.

Timofey Sitnikov 2021-06-06T01:55:54.104500Z

@seancorfield, I figured it out and I felt stupid so I deleted the question. Basically, I just needed to get the first then the (:account/password (first (account/get-account-by-email "<mailto:tony@example.com|tony@example.com>")).

Timofey Sitnikov 2021-06-06T02:01:42.106Z

Actually, I looking through https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.659/doc/getting-started, wow, I can provide the {:builder-fn rs/as-unqualified-lower-maps} then I get the simples map.

seancorfield 2021-06-06T02:04:53.106600Z

If you only want one row, use execute-one! (that's discussed in Getting Started).

seancorfield 2021-06-06T02:05:13.107100Z

Please try to work with the default and get used to qualified keywords first.

seancorfield 2021-06-06T02:05:31.107500Z

I wish more Clojurians would use qualified keys in maps 😐

Timofey Sitnikov 2021-06-06T02:16:58.112Z

@seancorfield, OK, so the most idiomatic approach is to use qualified keys, that is the answer I have been looking for, I just need to take the (first ... of the vectors since I like the find-by-keys query 😎

😀 1
Timofey Sitnikov 2021-06-06T02:20:09.112400Z

I tried it, but kept on scratching my head why it did not work and I could not find the function, now I know, need to use the development branch. 😂

seancorfield 2021-06-06T02:28:12.113300Z

Ah, yes, if you're using find-by-keys, the assumption is you'll get a sequence of rows.

1
seancorfield 2021-06-06T02:29:14.115200Z

For the example you gave above, you could use destructuring to get at the password in a simple binding:

(let [[{:account/keys [password]}] (sql/find-by-keys ...)]
  ... password ..)

seancorfield 2021-06-06T02:30:15.115800Z

(and it'll be nil if no rows matched)

Timofey Sitnikov 2021-06-06T02:33:45.118400Z

Ahhhh, destucturing, I am having a hard time getting used to it, one day I will get it. Seems magical 🪄. I am also trying to get comfortable with using db as immutable db, its hard to break bad habits ...

seancorfield 2021-06-06T02:40:40.118500Z

If you're using the CLI and deps.edn, you can rely on :git/url versions so you can test it direct from source.

1