| Copyright | (c) Soostone Inc 2020 |
|---|---|
| License | AllRightsReserved |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Napkin.Parse.Interpolation.Mustache
Description
Synopsis
- interpolateBackend :: (MonadIO m, MustacheBackend b) => InterpreterInstance -> b -> Text -> Text -> SqlTemplateVariables -> m (Either InterpolationError Text)
- interpolate :: Text -> Text -> SqlTemplateVariables -> Either InterpolationError Text
- initInterpreterForMustache :: MonadIO m => LogOptions -> m InterpreterInstance
Documentation
interpolateBackend :: (MonadIO m, MustacheBackend b) => InterpreterInstance -> b -> Text -> Text -> SqlTemplateVariables -> m (Either InterpolationError Text) #
Substitutes variables in mustache template. Supports Haskell function interpolation in form of mustache lambdas.
For example, following mustache template:
select {{#selExp}}[nonAlias $ varString ("column_" ++ show n) | n <- [1..3]]{{/selExp}} from dual
will be converted to
select "column_1", "column_2", "column_3" from dual
when using Postgres, but to
selectcolumn_1,column_2,column_3from dual
when using BigQuery as a backend.
Full list of supported lambdas:
- sExp - generates
SExp- almost any term in SQL syntax isSExp - selExp - generates [
AliasSExp] - represends one or many select clauses - fromExp - generates
From- represents a relation with attached "from" keyword - relAsExp - generates
Relation- represents a relation without an alias - relExp - generates
AliasRelation- represents a relation with its alias - queryExp - generates
Query- full SQL query - strExp - generates
String- will be inserted as is
Arguments
| :: Text | Name of the template (important for error reporting) |
| -> Text | Text of the template |
| -> SqlTemplateVariables | List of variables to use for a substitution process |
| -> Either InterpolationError Text |
Substitutes variables in mustache template. Does not supports Haskell function interpolation.
initInterpreterForMustache :: MonadIO m => LogOptions -> m InterpreterInstance #
Creates an instance of the Haskell interpreter to use for Mustache templating purposes.