package caqti

  1. Overview
  2. Docs
Unified interface to relational database libraries

Install

dune-project
 Dependency

Authors

Maintainers

Sources

caqti-v2.3.2.tbz
sha256=8f6c1724b59ac22a5c657c9e53b9a1706e39ecd462e82958b0cea88e43f0aba7
sha512=75b968ab37ae94cadcaabbcce0f91b1ffa4334ed69e441bdeb823077eb7675264282efb0fab3baaaad446582cfb427769e19f22c8c194a316ac2248c3fba5cf8

doc/caqti.template/Caqti_template/Query/Infix/index.html

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 Query.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).