Crates.io | sqlparser-mysql |
lib.rs | sqlparser-mysql |
version | 0.0.2 |
source | src |
created_at | 2024-03-17 13:41:37.795766 |
updated_at | 2024-04-16 07:26:40.835151 |
description | A SQL parser for MySQL with nom. |
homepage | https://github.com/xring/sqlparser-mysql |
repository | https://github.com/xring/sqlparser-mysql.git |
max_upload_size | |
id | 1176503 |
size | 521,838 |
A SQL parser for MySQL with nom. Written in Rust.
Please note that this repository is currently under active development. As such, it is subject to potentially disruptive changes without prior notice. We are working hard to improve the project and make it more robust. However, during this phase, we might introduce significant modifications to the codebase, features, and functionality.
We encourage users and contributors to keep this in mind when using, forking, or contributing to this project. Your understanding and patience are greatly appreciated as we continue to evolve this project.
Stay tuned for updates, and feel free to reach out or contribute to the development process!
This project is in a pre-release state. It may contain incomplete features, bugs, and unexpected behaviors. Use it at your own risk.
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);
The output should be:
AST: Select(
SelectStatement {
tables: [
Table {
name: "table_1",
alias: None,
schema: None,
},
],
distinct: false,
fields: [
Col(
Column {
name: "a",
alias: None,
table: None,
function: None,
},
),
Col(
Column {
name: "b",
alias: None,
table: None,
function: None,
},
),
Value(
Literal(
LiteralExpression {
value: Integer(
123,
),
alias: None,
},
),
),
Col(
Column {
name: "myfunc(b)",
alias: None,
table: None,
function: Some(
Generic(
"myfunc",
FunctionArguments {
arguments: [
Column(
Column {
name: "b",
alias: None,
table: None,
function: None,
},
),
],
},
),
),
},
),
],
join: [],
where_clause: Some(
LogicalOp(
ConditionTree {
operator: And,
left: ComparisonOp(
ConditionTree {
operator: Greater,
left: Base(
Field(
Column {
name: "a",
alias: None,
table: None,
function: None,
},
),
),
right: Base(
Field(
Column {
name: "b",
alias: None,
table: None,
function: None,
},
),
),
},
),
right: ComparisonOp(
ConditionTree {
operator: Less,
left: Base(
Field(
Column {
name: "b",
alias: None,
table: None,
function: None,
},
),
),
right: Base(
Literal(
Integer(
100,
),
),
),
},
),
},
),
),
group_by: None,
order: Some(
OrderClause {
columns: [
(
Column {
name: "a",
alias: None,
table: None,
function: None,
},
Desc,
),
(
Column {
name: "b",
alias: None,
table: None,
function: None,
},
Asc,
),
],
},
),
limit: None,
},
)
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);