napkin-0.5.14
Copyright(c) Soostone Inc 2020
LicenseAllRightsReserved
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Napkin.Parse.Interpolation.Mustache

Description

 
Synopsis

Documentation

interpolate' :: (MonadIO m, MustacheBackend b) => InterpolationMode -> InterpreterInstance -> b -> SourceLocation -> Text -> SqlTemplateVariables -> m (Either InterpolationError Text) #

Substitutes variables in mustache template. Supports Haskell function interpolation in form of mustache sections.

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 sections:

  • sExp - generates SExp - almost any term in SQL syntax is SExp
  • selExp - generates [Alias SExp] - represents 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

:: MonadIO m 
=> InterpolationMode

Level of interpolation engine strictness

-> SourceLocation

Location of the template (important for error reporting)

-> Text

Text of the template

-> SqlTemplateVariables

List of variables to use for a substitution process

-> m (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.