The interface of select_one_f_maybe is a bit unflexible:
val select_one_f_maybe : db -> ('a -> 'b result) -> ('c, 'a, 'b option result) expression -> 'c
It forces f to transform the query result, rather than the result option. It then forces the option onto the result of f.
I propose to add a more flexible version, with the following signature:
val select_one_maybe_f : db -> ('a option -> 'b result) -> ('c, 'a, 'b result) expression -> 'c
This one passes the whole option to f, and f has full control over the result type.
Among others, this would enable the implementation of an "exists" function that returns true if there is a result row and false if the result was empty:
let select_exists db sql =
S.select_one_maybe_f db (fun r -> r <> None) sql
Currently, it is impossible to define such a function in a generic way (i.e. for arbitrary SQL expressions with an arbitrary number of arguments), but the addition of select_one_maybe_f would enable that possibility.
The interface of
select_one_f_maybe
is a bit unflexible:It forces
f
to transform the query result, rather than the result option. It then forces the option onto the result off
.I propose to add a more flexible version, with the following signature:
This one passes the whole option to
f
, andf
has full control over the result type.Among others, this would enable the implementation of an "exists" function that returns
true
if there is a result row andfalse
if the result was empty:Currently, it is impossible to define such a function in a generic way (i.e. for arbitrary SQL expressions with an arbitrary number of arguments), but the addition of
select_one_maybe_f
would enable that possibility.