package caqti

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

caqti-v2.3.0.tbz
sha256=4dadf33904c9fd25065dbf6739aa0a9eaaaea000c6981c17a534b475dd5c3891
sha512=13c1cbeff3ee0e54ed1cc8f8df5f7660c292d5d50faa9480916f3c7e578961ab3b3779395c0664346cf42509f7b98d986e8377133542869a462288d6c0e34cbf

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