package caqti
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=b8ea432820154ec095132c4f7b244b06cd8553e0b2035185b844d9c4f30af8bb
sha512=b7e3ad8e6a9b587db2d517e15cd42df2945148f9223b2fa6f4bc2bcdd2709d53549cca4b65e54511d22466e4c9aa7f0b9c17305a07505519d8bf81d95de629b8
doc/caqti.template/Caqti_template/Query_fmt/index.html
Module Caqti_template.Query_fmt
Source
Format-based query construction.
The type of a function which formats values of type 'a
or fragments based on an input of type 'a
.
qprintf
allows building Caqti queries using a printf-style interface.
When using qprintf
, you can use the query
, quote
, env
and param
printers from this module to generate the corresponding query fragments.
In addition, you can use the "Q" and "E" string tags to delimit portions of the formatting string that should be interpreted as quotes and environment variables, respectively. The "Q" and "E" tags can not be nested: within the tags, qprintf
behaves no differently than Format.asprintf
and will generate a string, not a query (only when the tag is closed does the string get converted into a query).
The two following calls to qprintf
:
qprintf "FUNC(@{<Q>Quoted value with %d format(s)})" 1
and
qprintf "FUNC(%a)" quote (Format.asprintf "Quoted value with %d format(s)" 1)
are functionally equivalent. Both compute
S [L "FUNC("; Q "Quoted value with 1 format(s)"; L ")"]
but the first one is nicer to work with.
kqprintf
is the continuation-passing version of qprintf
(like Format.kasprintf
for Format.asprintf
).
You usually want qprintf
instead.
query
can be used with qprintf
to embed a query that was already parsed in the format string. Direct use of query
should be rare, and param
, env
, or quote
should be used instead when possible.
Using query
with any other formatter will ignore the query and instead print a dummy value (currently "... SQL FRAGMENT ..."
) instead.
Value Formatters
The following formatters emit values of basic field types by passing them as parameters. This is done by emitting a Caqti_template.Query.V
node with a appropriate field type.