Skip to main content

Module sql_templates

Module sql_templates 

Source
Expand description

SQL template extraction from database handlers.

This module extracts SQL generation patterns from the database handlers and stores them as metadata in the compiled schema.

For each rich scalar type and its operators, we:

  1. Call the database handler’s generate_extended_sql() with mock data
  2. Normalize the generated SQL to a template format
  3. Store the templates for runtime SQL generation

§Template Format

Templates use placeholders:

  • $field - The JSONB field reference (e.g., data->>'email')
  • $1, $2, etc. - Parameter placeholders (database-specific)

§Example

For EmailDomainEq on PostgreSQL:

  • Input: field_sql = “data->>‘email’”, domain = “example.com”
  • Handler output: “SPLIT_PART(data->>‘email’, ‘@’, 2) = $1”
  • Template: “SPLIT_PART($field, ‘@’, 2) = $1”

Functions§

build_sql_templates_metadata
Build SQL templates metadata for rich filter types.
extract_operator_templates
Extract SQL templates for a specific operator from all database handlers.