Skip to main content

Module rules

Module rules 

Source
Expand description

Static analysis rule engine for SQL queries.

This module provides a parallel rule execution engine that analyzes SQL queries for performance issues, style violations, and security vulnerabilities. Rules are implemented as types that implement the Rule trait.

§Architecture

┌─────────────┐     ┌──────────────┐     ┌─────────────┐
│  Queries    │────▶│  RuleRunner  │────▶│   Report    │
└─────────────┘     └──────────────┘     └─────────────┘
                           │
                    ┌──────┴──────┐
                    │   Rules     │
                    │  (parallel) │
                    └─────────────┘

The RuleRunner executes all enabled rules in parallel using rayon, collecting violations into an AnalysisReport.

§Rule Categories

  • Performance (PERF001-PERF019) - Query optimization issues
  • Style (STYLE001-STYLE004) - Best practice violations
  • Security (SEC001-SEC008) - Dangerous operations
  • Schema (SCHEMA001-SCHEMA003) - Schema validation (requires schema)

§Configuration

Rules can be disabled or have their severity modified via RulesConfig:

[rules]
disabled = ["STYLE001"]

[rules.severity]
PERF001 = "error"

§Implementing Custom Rules

use sql_query_analyzer::{
    query::Query,
    rules::{Rule, RuleCategory, RuleInfo, Severity, Violation}
};

pub struct MyRule;

impl Rule for MyRule {
    fn info(&self) -> RuleInfo {
        RuleInfo {
            id:       "CUSTOM001",
            name:     "My custom rule",
            severity: Severity::Warning,
            category: RuleCategory::Performance
        }
    }

    fn check(&self, query: &Query, query_index: usize) -> Vec<Violation> {
        vec![]
    }
}

Modules§

schema_aware

Structs§

AnalysisReport
Complete analysis report containing all violations.
RuleInfo
Metadata about a rule for identification and configuration.
RuleRunner
Parallel rule execution engine.
Violation
A single rule violation found in a query.

Enums§

RuleCategory
Category of a rule for grouping and filtering.
Severity
Severity level of a rule violation.

Traits§

Rule
Trait for implementing SQL analysis rules.