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§
- issue_
ice  - Construct an “Internal compiler error” issue, containing the current file and line
 - issue_
todo  - Construct an “Not yet implemented” issue, containing the current file and line
 
Structs§
- Alter
Table  - Represent an alter table statement
 - Create
Function  - Representation of Create Function Statement
 - Create
Table  - Represent a create table statement
 - Create
Trigger  - Represent a create trigger statement
 - Create
View  - Represent a create view statement
 - Data
Type  - Type of data
 - Delete
 - Represent a delete statement
 - Drop
Database  - Represent a drop database statement
 - Drop
Event  - Represent a drop event statement
 - Drop
Function  - Represent a drop function statement
 - Drop
Index  - Represent a drop index statement.
 - Drop
Procedure  - Represent a drop procedure statement
 - Drop
Server  - Represent a drop server statement
 - Drop
Table  - Represent a drop table statement
 - Drop
Trigger  - Represent a drop trigger statement
 - Drop
View  - Represent a drop view statement
 - Foreign
KeyOn  - Action to perform on events on foreign keys
 - Fragment
 - Identifier
 - Simple identifier in code it derefs to its string value
 - Index
Col  - Specify a column for an index, together with a with
 - Index
Hint  - Insert
Replace  - Representation of Insert or Replace Statement
 - Insert
Replace OnDuplicate KeyUpdate  - Insert
Replace Set  - Insert
Replace SetPair  - Issue
 - An issue encountered during parsing, or later stages
 - Issue
Handle  - Issues
 - OnConflict
 - Parse
Options  - Options used when parsing sql
 - Qualified
Name  - Rename
Table  - Represent a rename table statement
 - SString
 - A string with attached span
 - Select
 - Representation of select Statement
 - Select
Expr  - Value in select
 - Table
ToTable  - Truncate
Table  - Represent a truncate table statement
 - Union
 - Union statement
 - Union
With  - Right hand side of a union expression
 - Update
 - Representation of replace Statement
 - When
 - When part of CASE
 - With
Block  - With
Query  - Represent a with query statement
 
Enums§
- Alter
Column Action  - Enum of alterations to perform on a column
 - Alter
Specification  - Enum of alterations to perform on a table
 - Binary
Operator  - Binary operator to apply
 - Create
Algorithm  - Special algorithm used for table creation
 - Create
Definition  - Definition in create table
 - Create
Option  - Options for create statement
 - Data
Type Property  - A property on a datatype
 - Delete
Flag  - Flags for deletion
 - Expression
 - Representation of an expression
 - Foreign
KeyOn Action  - Action to take on event for foreign key
 - Foreign
KeyOn Type  - When to take a foreign key action
 - Function
 - Function to execute
 - Identifier
Part  - Part of a full identifier
 - Index
Hint For  - Index
Hint Type  - Index
Hint Use  - Index
Option  - Option on an index
 - Index
Type  - Type of index to add
 - Insert
Replace Flag  - Flags for insert
 - Insert
Replace Type  - Is
 - Type of is expression
 - Join
Specification  - Specification for join
 - Join
Type  - Type of join
 - Level
 - Level of an issues
 - OnConflict
Action  - OnConflict
Target  - SQLArguments
 - What kinds or arguments
 - SQLDialect
 - What sql diarect to parse as
 - Select
Flag  - Flags specified after SELECT
 - Statement
 - SQL statement
 - Table
Option  - Options on created table
 - Table
Reference  - Reference to table in select
 - Time
Unit  - Units of time
 - Type
 - Type of datatype
 - Unary
Operator  - Unary operator to apply
 - Union
Type  - Type of union to perform
 - Update
Flag  - Flags specified after “UPDATE”
 - Variable
 - Function to execute
 
Traits§
- OptSpanned
 - Compute an optional byte span of an ast fragment
 - Spanned
 - Compute byte span of an ast fragment
 
Functions§
- parse_
statement  - 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_
statements  - 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§
- Span
 - Byte span of ast fragment