Crate sql_parse

Source
Expand description

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 sql_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);

Macros§

  • Construct an “Internal compiler error” issue, containing the current file and line
  • Construct an “Not yet implemented” issue, containing the current file and line

Structs§

Enums§

Traits§

  • Compute an optional byte span of an ast fragment
  • Compute byte span of an ast fragment

Functions§

  • Parse a single statement, A statement may be returned even if there where parse errors. The statement is free of errors if no Error issues are added to issues
  • Parse multiple statements, return an Vec of Statements even if there are parse errors. The statements are free of errors if no Error issues are added to issues

Type Aliases§

  • Byte span of ast fragment