Expand description
SQL template preprocessing for Jinja2 and dbt-style templates.
This module provides preprocessing support for templated SQL, allowing FlowScope to analyze SQL files that use Jinja2 syntax or dbt macros.
§Architecture
Templating is a preprocessing step that runs before SQL parsing:
Templated SQL → [templater] → Raw SQL → [parser] → AST → [analyzer] → Lineage§Modes
- Raw: No templating, SQL is passed through unchanged (default)
- Jinja: Standard Jinja2 template rendering with strict variable checking
- Dbt: Jinja2 with dbt builtin macros (
ref,source,config,var, etc.)
§Example
use flowscope_core::templater::{template_sql, TemplateConfig, TemplateMode};
use std::collections::HashMap;
// dbt-style template
let template = r#"
{{ config(materialized='table') }}
SELECT * FROM {{ ref('users') }}
WHERE created_at > '{{ var("start_date", "2024-01-01") }}'
"#;
let config = TemplateConfig {
mode: TemplateMode::Dbt,
context: HashMap::new(),
};
let rendered = template_sql(template, &config).unwrap();
assert!(rendered.contains("FROM users"));Structs§
- Template
Config - Configuration for SQL template preprocessing.
Enums§
- Template
Error - Errors that can occur during template rendering.
- Template
Mode - Templating mode for SQL preprocessing.
Functions§
- template_
sql - Renders a SQL template according to the specified configuration.