package caqti

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Query.InfixSource

This 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)
Sourceval (@++) : t -> t -> t

An alias for cat.

Sourceval (^++) : string -> t -> t

pfx ^++ q is q prefixed with the literal fragment pfx, i.e. cat (lit pfx) q.

Sourceval (++^) : t -> string -> t

q ++^ sfx is q suffixed with the literal fragment sfx, i.e. cat q (lit sfx).

OCaml

Innovation. Community. Security.