Hello,
I’m trying to do something trivial - write a select query that joins 2 tables and returns a list of the results
But I can’t come up with a query with the appropriate syntax, does anyone have experience with ppx_rapper
?
From the github issue Using %list with function_out · Issue #28 · roddyyaga/ppx_rapper · GitHub :
I have 2 tables, with an id
column and want to join them and return the results:
let a =
[%rapper
get_many
{sql|
SELECT
@int{a.id},
@string{a.name},
@int{b.id},
@string{b.name}
FROM public.table1 as a
INNER JOIN public.table2 as b
ON a.b_id = b.id
WHERE
a.id IN (%list{%string{ids}})
|sql}]
this works, but it results in a tuple, which is not great (int * string * int * string) list
record_out
doesn’t work, because id
is the same in both tables:
Variable id is bound several times in this matching
function_out
doesn’t work, because I get
Unbound value loaders
Not sure where this is coming from?
I noticed that not using %list
compiles the ppx (WHERE a.id = %string{id}
) (but doesn’t work for my use case)
Is it possible to use %list
and function_out
somehow?