Skip to content

plpipes.action.driver.sql.jinja2#

This module contains the logic for generating SQL code using the Jinja2 template system. It provides several convenient helpers for easing SQL generation.

render_template(src, global_vars) #

Render a Jinja2 template with the given source and global variables.

Parameters:

Name Type Description Default
src str

The source template string.

required
global_vars dict

A dictionary of global variables to be passed to the template.

required

Returns:

Name Type Description
str

The rendered template output.

Source code in src\plpipes\action\driver\sql\jinja2.py
def render_template(src, global_vars):
    """Render a Jinja2 template with the given source and global variables.

    Args:
        src (str): The source template string.
        global_vars (dict): A dictionary of global variables to be passed to the template.

    Returns:
        str: The rendered template output.
    """
    env = jinja2.Environment()
    env.filters['cols'] = _join_columns
    env.filters['esc'] = _escape
    env.filters['quote'] = _quote
    env.filters['debug'] = _debug
    env.filters['pluralize'] = _pluralize
    env.filters['singularize'] = _singularize
    env.globals['cfg_tree'] = _cfg_tree
    env.globals['cfg_list'] = _cfg_list
    env.globals['logging'] = logging
    return env.from_string(src).render(**global_vars)