Overview
IntegrationsPricing

SQL template syntax

Blacksmith exposes a Python / Django-syntax like templating-language when working with SQL files. This is a convenient way to generate SQL dynamically interpolating the template with contextual data and returning the compiled SQL file.

The templating-language involves four constructs.

Variables are surrounded by {{ and }} like this:

INSERT INTO orders (amount, user_id) VALUES
  ({{ order.amount }}, '{{ user.id }}');

Tags provide arbitrary logic in the rendering process. Tags are surrounded by {% and %} like this:

{% if order %}
  INSERT INTO orders (amount, user_id) VALUES
    ({{ order.amount }}, '{{ user.id }}');
{% endif %}

Filters transform the values of variables with tag arguments. They look like this:

INSERT INTO orders (amount, user_id) VALUES
  ({{ order.amount|floatformat:2 }}, '{{ user.id }}');

Comments look like this:

{# This won't be compiled #}
Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the repository. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Thank you for your contributions!