HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulebeam-core-0.11.1.0Haskell2010

Database.Beam.Query.CustomSQL

Allows the creation of custom SQL expressions from arbitrary string-like values.

Simply write a polymorphic function with an arbitrary number of arguments, all of the same type, and returns a value of the same type. The type will have instances of Monoid and IsString.

For example, to implement a function MYFUNC that takes three arguments

myFuncImpl :: (Monoid a, IsString a) => a -> a -> a -> a

Then, apply customExpr_ to your function. This will result in a function with the same arity, that takes in and returns QGenExprs instead of generic as.

The returned function is polymorphic in the types of SQL expressions it will accept, but you can give it a more specific signature. For example, to mandate that we receive two Int32s and a Text and return a Bool.

myFunc_ :: QGenExpr e ctxt s Int32 -> QGenExpr e ctxt s Int32 -> QGenExpr e ctxt s T.Text -> QGenExpr e ctxt s Bool
myFunc_ = customExpr_ myFuncImpl

Semantically, the expression builder function (myFuncImpl in this case) is called with arguments representing SQL expressions, that, when evaluated, will evaluate to the result of the expressions supplied as arguments to customExpr_. See the section on https://haskell-beam.github.io/beam/user-guide/extensibility/extensibility in the user guide for example usage.

  • 2 classes
  • 2 values

The customExpr_ function

1 declaration
classclass IsCustomExprFn fn res | res -> fn where
#

Methods

Instances2IsCustomExprFn
  • BeamSqlBackendHasCustomSyntax be => IsCustomExprFn (CustomSqlSnippet be) (QGenExpr ctxt be s res)Defined in beam-core-0.11.1.0 · Database.Beam.Query.CustomSQL
  • (IsCustomExprFn a res, BeamSqlBackendHasCustomSyntax be) => IsCustomExprFn (CustomSqlSnippet be -> a) (QGenExpr ctxt be s r -> res)Defined in beam-core-0.11.1.0 · Database.Beam.Query.CustomSQL

Type-inference help

valuevalueExpr_ :: QExpr be s a -> QExpr be s a
#

Force a QGenExpr to be typed as a value expression (a QExpr). Useful for getting around type-inference errors with supplying the entire type.

valueagg_ :: QAgg be s a -> QAgg be s a
#

Force a QGenExpr to be typed as an aggregate. Useful for defining custom aggregates for use in aggregate_.

For backends

1 declaration
classclass (Monoid (CustomSqlSyntax syntax), Semigroup (CustomSqlSyntax syntax), IsString (CustomSqlSyntax syntax)) => IsCustomSqlSyntax syntax where
#

A type-class for expression syntaxes that can embed custom expressions.

Associated types

Methods

  • customExprSyntax :: CustomSqlSyntax syntax -> syntax

    Given an arbitrary string-like expression, produce a syntax that represents the ByteString as a SQL expression.

  • renderSyntax :: syntax -> CustomSqlSyntax syntax

    Given an arbitrary syntax, produce a string-like value that corresponds to how that syntax would look when rendered in the backend.

Instances1IsCustomSqlSyntax