Fork me on GitHub
#sql
<
2018-01-20
>
Will01:01:42

I queried an object and assigned it to a variable called link-object using the let macro but I’m not sure how access the columns in clojure. Here is a print out of the object from clojure: ({:id 2, :number 5 , :link_id 7, :account 30}) I tried this (get :number link-object)

seancorfield01:01:54

The result of a query is a sequence of hash maps. If you want the :number from the first row: (:number (first link-object))

seancorfield01:01:33

If you know the primary key of a row, you can use jdbc/get-by-id to get a single row.

seancorfield01:01:12

If you only want the first result from a query, you can specify {:result-set-fn first} as an option (the last argument).

seancorfield01:01:28

Also, it'll help you get into the Clojure mindset @josmith2016 if instead of "assigned it to a variable" you think "bound the value to a symbol" -- because they're not really variables and you're not assigning to them.

Will01:01:44

Thank you that worked!