Query.Infix
SourceThis module provides a terser way to compose queries. As an example, consider the dynamic construction of a simple SELECT-request which extracts a list of named columns given a corresponding row type, and where conditions are given as query templates with any values embedded:
open Caqti_template.Create
type cond =
| Column_eq : string * 'a Caqti_template.Field_type.t * 'a -> cond
let query_of_cond = function
| Column_eq (col, t, v) ->
Q.lit col @++ " = " ^++ Q.const t v
let make_simple_select conds columns row_type =
let query =
"SELECT " ^++ Q.concat ~sep:", " (List.map Q.lit columns) @++
" FROM $.foo" ^++
" WHERE " ^++ Q.concat ~sep:" AND " (List.map query_of_cond conds)
in
direct_gen T.(unit -->* row_type) (fun _ -> query)