Oak SQL Parser
High-performance incremental SQL parser for the oak ecosystem with flexible configuration, optimized for database query analysis and SQL processing.
🎯 Overview
Oak SQL is a robust parser for SQL, designed to handle complete SQL syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for database query analysis and SQL processing.
✨ Features
- Complete SQL Syntax: Supports all SQL features including modern specifications
- Full AST Generation: Generates comprehensive Abstract Syntax Trees
- Lexer Support: Built-in tokenization with proper span information
- Error Recovery: Graceful handling of syntax errors with detailed diagnostics
🚀 Quick Start
Basic example:
use ;
📋 Parsing Examples
Select Statement Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
println!;
Insert Statement Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
println!;
🔧 Advanced Features
Token-Level Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
println!;
Error Handling
use ;
let parser = new;
let source = new;
let result = parser.parse;
if let Some = result.result.err else
🏗️ AST Structure
The parser generates a comprehensive AST with the following main structures:
- SelectStatement: SELECT queries with columns, tables, conditions
- InsertStatement: INSERT statements with table and values
- UpdateStatement: UPDATE statements with table, sets, and conditions
- DeleteStatement: DELETE statements with table and conditions
- CreateTableStatement: CREATE TABLE statements with schema definitions
- Expression: Various expression types (comparison, logical, arithmetic)
📊 Performance
- Streaming: Parse large SQL files without loading entirely into memory
- Incremental: Re-parse only changed sections
- Memory Efficient: Smart AST node allocation
- Fast Recovery: Quick error recovery for better IDE integration
🔗 Integration
Oak SQL integrates seamlessly with:
- Database Tools: Build SQL query analyzers and optimizers
- IDE Support: Language server protocol compatibility for SQL
- Migration Tools: Analyze and transform database schemas
- Query Builders: Generate SQL from AST representations
- Data Analysis: Extract information from SQL queries
📚 Examples
Check out the examples directory for comprehensive examples:
- Complete SQL statement parsing
- Query analysis and optimization
- Schema extraction and validation
- Integration with development workflows
🤝 Contributing
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.