napkin-0.5.9
Copyright(c) Soostone Inc 2020
LicenseAllRightsReserved
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Napkin.Parse.Interpolation.Mustache

Description

 
Synopsis

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

select column_1, column_2, column_3 from dual

when using BigQuery as a backend.

Full list of supported lambdas:

  • sExp - generates SExp - almost any term in SQL syntax is SExp
  • selExp - generates [Alias SExp] - 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 Alias Relation - represents a relation with its alias
  • queryExp - generates Query - full SQL query
  • strExp - generates String - will be inserted as is

interpolate #

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.