qusql-parse 0.1.0

Parser for sql
Documentation
  • Coverage
  • 40.4%
    383 out of 948 items documented21 out of 36 items with examples
  • Size
  • Source code size: 375.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 36.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • antialize/sql-parse
    25 7 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • antialize

qusql-parse

crates.io crates.io License

Parse SQL into an AST

This crate provides an lexer and parser that can parse SQL into an Abstract Syntax Tree (AST). Currently primarily focused on MariaDB/Mysql.

Example code:

use qusql_parse::{SQLDialect, SQLArguments, ParseOptions, parse_statement, Issues};

let options = ParseOptions::new()
    .dialect(SQLDialect::MariaDB)
    .arguments(SQLArguments::QuestionMark)
    .warn_unquoted_identifiers(true);


let sql = "SELECT `monkey`,
           FROM `t1` LEFT JOIN `t2` ON `t2`.`id` = `t1.two`
           WHERE `t1`.`id` = ?";
let mut issues = Issues::new(sql);
let ast = parse_statement(sql, &mut issues, &options);

println!("{}", issues);
println!("AST: {:#?}", ast);

Features

  • Good error recovery: The parser implements reasonable error recovery and will continue parsing long expressions if an error is found within.
  • Code span annotations: All AST notes implements Spanned that yields a byte span within the code. This means that errors and warnings generated from the parsing can be precented to the user in a nice ways. Also users of the AST can generate more issues that can also similarly be presented nicely.
  • No dependencies: We use no-std with alloc, and has no other dependencies
  • No unsafe code: We use #![forbid(unsafe_code)] to guarantee no unsafe code.
  • Fast parsing: The parser is a hand written recursive decent parser. To speed up parser expressions are parsed using a O(1) shift reduce mechanism.