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};

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

let mut issues = Vec::new();

let sql = "SELECT `monkey`,
           FROM `t1` LEFT JOIN `t2` ON `t2`.`id` = `t1.two`
           WHERE `t1`.`id` = ?";

let ast = parse_statement(sql, &mut issues, &options);

println!("Issues: {:#?}", 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