Fork me on GitHub
#sql
<
2021-06-06
>
Timofey Sitnikov01:06:49

@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.

seancorfield01:06:59

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

seancorfield01:06:59

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

Timofey Sitnikov01:06:54

@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 "")).

Timofey Sitnikov02:06:42

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.

seancorfield02:06:53

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

seancorfield02:06:13

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

seancorfield02:06:31

I wish more Clojurians would use qualified keys in maps 😐

Timofey Sitnikov02:06:58

@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 😎

😀 3
seancorfield02:06:12

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

3
seancorfield02:06:14

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 ..)

seancorfield02:06:15

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

Timofey Sitnikov02:06:45

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 ...