oak-sql

Crates.iooak-sql
lib.rsoak-sql
version0.0.1
created_at2025-10-21 12:33:24.125928+00
updated_at2026-01-23 05:19:23.168637+00
descriptionSQL database query language parser with support for standard SQL syntax and database operations.
homepagehttps://github.com/ygg-lang/oaks
repositoryhttps://github.com/ygg-lang/oaks
max_upload_size
id1893745
size100,551
FuckQQ (fqq)

documentation

https://docs.rs/oak-sql

README

Oak SQL Parser

Crates.io Documentation

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 oak_sql::{Parser, SqlLanguage, SourceText};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let parser = Parser::new();
    let source = SourceText::new(r#"
        SELECT u.id, u.name, p.title
        FROM users u
        JOIN posts p ON u.id = p.user_id
        WHERE u.active = true
        ORDER BY u.created_at DESC
        LIMIT 10;
    "#);
    
    let result = parser.parse(&source);
    println!("Parsed SQL successfully.");
    Ok(())
}

📋 Parsing Examples

Select Statement Parsing

use oak_sql::{Parser, SqlLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
    SELECT id, name, email
    FROM customers
    WHERE country = 'USA' AND age > 21
    ORDER BY name ASC
    LIMIT 100;
"#);

let result = parser.parse(&source);
println!("Select statement parsed successfully.");

Insert Statement Parsing

use oak_sql::{Parser, SqlLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
    INSERT INTO products (name, price, category)
    VALUES ('Laptop', 999.99, 'Electronics');
"#);

let result = parser.parse(&source);
println!("Insert statement parsed successfully.");

🔧 Advanced Features

Token-Level Parsing

use oak_sql::{Parser, SqlLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new("SELECT * FROM users WHERE id = 1;");
let result = parser.parse(&source);
println!("Token parsing completed.");

Error Handling

use oak_sql::{Parser, SqlLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
    SELECT name, 
    FROM users
    WHERE id = 1;
"#);

let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
    println!("Parse errors found: {:?}", errors);
} else {
    println!("Parsed successfully.");
}

🏗️ 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.

Commit count: 80

cargo fmt