Declaring types that have many columns?
rawleyfowler opened this issue · 3 comments
rawleyfowler commented
Thank you for this amazing package. I am following the example in the examples
directory, but I cannot figure out how to create a type that doesn't fall within tup2 tup3 or tup4
for example if I had a type:
module Post = struct
type t = {
uri : string;
title : string;
content : string;
created_at : Ptime.t;
updated_at : Ptime.t
}
end
How can I use this type with Caqti, if the type didn't have created_at
or updated_at
I could write it like:
let post =
let open Post in
let encode {uri; title; description} = Ok (uri, title, description) in
let decode (uri, title, description) = Ok {uri; title; description} in
let _t = Caqti_type.(tup3 string string string) in
custom ~encode ~decode _t
How can I declare a record type that is larger than tup4?
anmonteiro commented
The tupN
combinators can be nested. See #47 (comment)
paurkedal commented
Yes, nesting is the only way to handle more than 4 columns with the current interface.
rawleyfowler commented
Okay, that makes sense. So basically:
let _t = Caqti_type.(tup2 (tup3 string string string) (tup2 ptime ptime))
Thanks!