Crate sqlparser_mysql

Source
Expand description

§SQL Parser for MySQL with Rust

This crate provides parser that can parse SQL into an Abstract Syntax Tree.

§Example parsing SQL

use sqlparser_mysql::parser::Parser;
use sqlparser_mysql::parser::ParseConfig;

let config = ParseConfig::default();
let sql = "SELECT a, b, 123, myfunc(b) \
           FROM table_1 \
           WHERE a > b AND b < 100 \
           ORDER BY a DESC, b";

// parse to a Statement
let ast = Parser::parse(&config, sql).unwrap();

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

§Creating SQL text from AST

This crate allows users to recover the original SQL text (with comments removed, normalized whitespace and identifier capitalization), which is useful for tools that analyze and manipulate SQL.

use sqlparser_mysql::parser::Parser;
use sqlparser_mysql::parser::ParseConfig;

let sql = "SELECT a FROM table_1";
let config = ParseConfig::default();

// parse to a Statement
let ast = Parser::parse(&config, sql).unwrap();

// The original SQL text can be generated from the AST
assert_eq!(ast.to_string(), sql);

Re-exports§

pub use self::parser::*;

Modules§

base
das
dds
dms
parser