Fork me on GitHub
#hugsql
<
2021-06-02
>
Zaymon02:06:43

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)"}

Zaymon02:06:58

-- 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.summers02:06:29

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…?

Zaymon02:06:14

That worked… Thanks!

curtis.summers02:06:22

You’re welcome!

Zaymon02:06:23

Love it when it’s something simple like that