Crates.io | sql-parse |
lib.rs | sql-parse |
version | 0.22.1 |
source | src |
created_at | 2022-02-24 07:57:09.05043 |
updated_at | 2024-11-11 11:09:47.98416 |
description | Parser for sql |
homepage | https://github.com/antialize/sql-parse/ |
repository | https://github.com/antialize/sql-parse/ |
max_upload_size | |
id | 538312 |
size | 353,758 |
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: {}", issues);
println!("AST: {:#?}", ast);
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.#![forbid(unsafe_code)]
to guarantee no unsafe code.O(1)
shift reduce mechanism.