Jinja the SQL way of the Ninja
Using Jinja templates and Python to generate re-usable SQL queries
There is many use for dynamically generating SQL queries such as increased code legibility or re-use. Jinja is a Python templating engine that can be used for just that purpose.
Introduction to Jinja Templates
What is a Jinja Template
Jinja is a templating engine for Python similar to twig, or Django templates. Jinja templates are traditionally used in HTML/web development for the creation of views using Flask as the web framework. Other Python software such as Ansible also leverage Jinja as a templating engine.
Templating engines are often used to help with the separation of concerns within MVC (Model View Controller) to separate the data layer, business logic and the presentation layer of the information.
What features are available
Jinja templates offer some basic programming functionalities, such as Variable substitutions, for loops, functions calls, filters, as well as the ability to extend base…