hugsql

Zaymon 2021-06-02T02:39:43.002Z

Hi, I have this HugSql query:

-- :name find-friendships :? :*
-- :doc find all friends for a given user
select (u.id, u.first_name, u.last_name) from friendships
join users u on u.id = friendships.user2
where user1 = :user_id
Is there a way to get the data back as a map instead of {:row "(someid, name, lastName)"}

Zaymon 2021-06-02T02:41:58.002100Z

-- Let's specify some columns with the
-- identifier list parameter type :i* and
-- use a value list parameter type :v* for SQL IN()
-- :name characters-by-ids-specify-cols :? :*
-- :doc Characters with returned columns specified
select :i*:cols from characters
where id in (:v*:ids)
I’ve seen this snippet in the docs, but is there a way to specify the columns that isn’t dynamic? I never need a variable list of columns for this query

curtis.summers 2021-06-02T02:44:29.002300Z

Why the parentheses around your selected columns? This is creating a tuple, I think. Can you change your SQL to select u.id, u.first_name, u.last_name from…?

Zaymon 2021-06-02T02:45:14.002500Z

That worked… Thanks!

curtis.summers 2021-06-02T02:45:22.002700Z

You’re welcome!

Zaymon 2021-06-02T02:45:23.002900Z

Love it when it’s something simple like that