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:
- Call the database handler’s generate_extended_sql() with mock data
- Normalize the generated SQL to a template format
- 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.