SQL File Loader¶
Load and cache SQL files with named statement support. SQL files can contain
multiple named statements separated by -- name: comments.
SQLFileLoader¶
- class sqlspec.loader.SQLFileLoader[source]¶
Bases:
objectLoads and parses SQL files with named SQL queries.
Loads SQL files containing named queries (using – name: syntax) and retrieves them by name.
- __init__(*, encoding='utf-8', storage_registry=None, runtime=None)[source]¶
Initialize the SQL file loader.
- Parameters:
storage_registry¶ (
StorageRegistry|None) – Storage registry for handling file URIs.runtime¶ (
ObservabilityRuntime|None) – Observability runtime for instrumentation.
- set_observability_runtime(runtime)[source]¶
Attach an observability runtime used for instrumentation.
- Return type:
- add_named_sql(name, sql, dialect=None)[source]¶
Add a named SQL query directly without loading from a file.
- get_query_text(name)[source]¶
Get raw SQL text for a query.
- Parameters:
- Return type:
- Returns:
Raw SQL text.
- Raises:
SQLFileNotFoundError – If query not found.