hasql-dynamic-statements-0.1.0.1: Toolkit for constructing Hasql statements dynamically

Safe HaskellNone
LanguageHaskell2010

Hasql.DynamicStatements.Snippet

Synopsis

Documentation

data Snippet Source #

Composable SQL snippet with parameters injected. Abstracts over placeholders and matching of encoders.

It has an instance of IsString, so having the OverloadedStrings extension enabled you can use string literals to construct it from string.

Here's an example:

selectSubstring :: Text -> Maybe Int64 -> Maybe Int64 -> Snippet
selectSubstring string from to =
  "select substring(" <> param string <>
  foldMap (\ x -> " from " <> param x) from <>
  foldMap (\ x -> " for " <> param x) to <>
  ")"

Having a decoder you can lift it into Statement using dynamicallyParameterized or directly execute it in Session using snippet.

param :: Default (Value param) => param -> Snippet Source #

Parameter encoded using an implicitly derived encoder from the type.

nullableParam :: Default (Value param) => Maybe param -> Snippet Source #

Nullable parameter encoded using an implicitly derived encoder from the type.

encoderAndParam :: Value param -> param -> Snippet Source #

Parameter with an explicitly defined encoder.

encoderAndNullableParam :: Value param -> Maybe param -> Snippet Source #

Nullable parameter with an explicitly defined encoder.