hasql-dynamic-statements
Library extending Hasql with a composable API for building SQL statements dynamically.
The core abstraction is Snippet, which allows you to construct SQL statements with parameters
injected in-place, automatically handling placeholders and encoder matching. This is particularly
useful when the structure of your SQL depends on runtime parameters.
Key features:
- Composable SQL snippets using
SemigroupandMonoidinstances - Automatic placeholder generation and parameter encoding
- Type-safe parameter injection with implicit encoder derivation
- Protection against common SQL construction bugs
- Support for conditional SQL structure based on parameters
Example:
selectSubstring :: Text -> Maybe Int32 -> Maybe Int32 -> Snippet
selectSubstring string from to =
"select substring(" <> param string <>
foldMap (\x -> " from " <> param x) from <>
foldMap (\x -> " for " <> param x) to <>
")"Modules
hasql-dynamic-statements-0.5.1.2
- Hasql
- DynamicStatements