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-PERF020) - Query optimization issues - Style (
STYLE001-STYLE004) - Best practice violations - Security (
SEC001-SEC008) - Dangerous operations - Schema (
SCHEMA001-SCHEMA004) - 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§
Structs§
- Analysis
Report - Complete analysis report containing all violations.
- Rule
Info - Metadata about a rule for identification and configuration.
- Rule
Runner - Parallel rule execution engine.
- Violation
- A single rule violation found in a query.
Enums§
- Rule
Category - Category of a rule for grouping and filtering.
- Severity
- Severity level of a rule violation.
Traits§
- Rule
- Trait for implementing SQL analysis rules.