| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.DynamicStatements.Snippet
Synopsis
- data Snippet
- param :: DefaultParamEncoder param => param -> Snippet
- encoderAndParam :: NullableOrNot Value param -> param -> Snippet
- sql :: ByteString -> Snippet
Documentation
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 construct it directly from string literals.
Here's an example:
selectSubstring :: Text -> Maybe Int32 -> Maybe Int32 ->SnippetselectSubstring string from to = "select substring(" <>paramstring <>foldMap(\ x -> " from " <>paramx) from <>foldMap(\ x -> " for " <>paramx) to <> ")"
Having a decoder you can lift it into Statement using
dynamicallyParameterized or directly execute it in
Session using
dynamicallyParameterizedStatement .
Instances
Instance details
Defined in Hasql.DynamicStatements.Snippet.Defs
Methods
fromString :: String -> Snippet #
param :: DefaultParamEncoder param => param -> Snippet Source #
Parameter encoded using an implicitly derived encoder from the type.
encoderAndParam :: NullableOrNot Value param -> param -> Snippet Source #
Parameter with an explicitly defined encoder.
sql :: ByteString -> Snippet Source #
SQL chunk in ASCII.