package caqti
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=ba4dfd5ff94376b5e003f682410b7b3b392c0bbaa0253679fe7671c2e07e895b
sha512=0416807fba620429ee4d64f3a6991238112e0e10dfba9703dced46cf332fd22135a9873007d025441228ce66fb192bf730d4bc776dd2c1a973d7604ab6e789e0
doc/caqti/Caqti_query_fmt/index.html
Module Caqti_query_fmtSource
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)})" 1and
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_query.t.V node with a appropriate field type.