arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Sql.QQ

Description

Internal to the arbiter packages. Not covered by the PVP.

The sql quasiquoter. It builds a Query whose text, parameters, and row decoder all come from one template. The stmt quasiquoter renders the text once and makes each distinct #{...} identifier a function argument.

Holes reference in-scope identifiers, like NeatInterpolation's ${var}:

  • ${x} splices a fragment: Text (raw clause or table name) or a Query () (its parameters interleave at the splice site), via ToFragment.
  • #{ident :: CInt8} emits one parameter hole and binds in-scope ident as its value. Maybe CInt8, [CInt8], and [Maybe CInt8] pick the nullable, array, and nullable-array encoders.
  • @{name :: CInt8} emits the identifier name and adds col "name" CInt8 to the decoder (Maybe CInt8 uses ncol). The quote's result type is Query () with no @{...} holes, Query of the bare value with one, and Query of a tuple with 2 to maxOutputHoles.

A ? in the template is literal SQL. Do not use it in a template with holes. The ?-placeholder form cannot tell it from a hole.

Synopsis

Documentation

sql :: QuasiQuoterSource #

The sql quasiquoter, valid in expression position.

stmt :: QuasiQuoterSource #

Like sql, but each distinct #{ident :: coltype} hole becomes a parameter of the result, in order of first appearance. The text is rendered once.

maxOutputHoles :: IntSource #

The most @{...} holes one quote decodes as a tuple.