Skip to main content

run_analyze

Function run_analyze 

Source
pub async fn run_analyze(
    params: AnalyzeParams,
    config: Config,
) -> AppResult<AnalyzeResult>
Expand description

Executes the complete SQL analysis pipeline.

This function orchestrates the entire analysis workflow:

  1. Schema Parsing: Reads and parses the schema file
  2. Query Parsing: Reads queries (from file or stdin) and parses them
  3. Static Analysis: Runs all enabled rules against the queries
  4. LLM Analysis (optional): Sends schema and queries to LLM for analysis

§Arguments

  • params - Analysis parameters including file paths and options
  • config - Application configuration with rule settings and LLM config

§Returns

An AnalyzeResult containing:

  • Exit code based on violation severity
  • Formatted static analysis output
  • Optional LLM analysis output
  • Optional dry-run information

§Errors

Returns an error if:

  • Schema or query files cannot be read
  • SQL parsing fails
  • LLM API call fails (when LLM is enabled)

§Example

use sql_query_analyzer::{
    app::{AnalyzeParams, run_analyze},
    cli::{Dialect, Format, Provider},
    config::Config
};

let params = AnalyzeParams {
    schema_path:   "schema.sql".to_string(),
    queries_path:  "queries.sql".to_string(),
    provider:      Provider::Ollama,
    api_key:       None,
    model:         None,
    ollama_url:    "http://localhost:11434".to_string(),
    dialect:       Dialect::Generic,
    output_format: Format::Text,
    verbose:       false,
    dry_run:       false,
    no_color:      false
};

let config = Config::default();
let result = run_analyze(params, config).await?;
println!("Exit code: {}", result.exit_code);