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

Represent an alter table statement

Representation of Create Function Statement

Represent a create table statement

Represent a create trigger statement

Represent a create view statement

Type of data

Represent a delete statement

Represent a drop database statement

Represent a drop event statement

Represent a drop function statement

Represent a drop procedure statement

Represent a drop server statement

Represent a drop table statement

Represent a drop trigger statement

Represent a drop view statement

Action to perform on events on foreign keys

Simple identifier in code it derefs to its string value

Specify a column for an index, together with a with

Representation of Insert or Replace Statement

An issue encountered during parsing, or later stages

Options used when parsing sql

A string with attached span

Representation of select Statement

Union statement

Right hand side of a union expression

Representation of replace Statement

When part of CASE

Enums

Enum of alterations to perform on a table

Binary operator to apply

Special algorithm used for table creation

Definition in create table

Options for create statement

A property on a datatype

Flags for deletion

Representation of an expression

Action to take on event for foreign key

When to take a foreign key action

Function to execute

Part of a full identifier

Option on an index

Type of index to add

Flags for insert

Type of is expression

Specification for join

Type of join

Level of an issues

What kinds or arguments

What sql diarect to parse as

Flags specified after SELECT

SQL statement

Options on created table

Reference to table in select

Type of datatype

Unary operator to apply

Type of union to perform

Flags specified after “UPDATE”

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 Definitions

Byte span of ast fragment