sqlparser/lib.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12
13//! # SQL Parser for Rust
14//!
15//! This crate provides an ANSI:SQL 2011 lexer and parser that can parse SQL
16//! into an Abstract Syntax Tree ([`AST`]). See the [sqlparser crates.io page]
17//! for more information.
18//!
19//! For more information:
20//! 1. [`Parser::parse_sql`] and [`Parser::new`] for the Parsing API
21//! 2. [`ast`] for the AST structure
22//! 3. [`Dialect`] for supported SQL dialects
23//!
24//! # Example
25//!
26//! ```
27//! use sqlparser::dialect::GenericDialect;
28//! use sqlparser::parser::Parser;
29//!
30//! let dialect = GenericDialect {}; // or AnsiDialect
31//!
32//! let sql = "SELECT a, b, 123, myfunc(b) \
33//! FROM table_1 \
34//! WHERE a > b AND b < 100 \
35//! ORDER BY a DESC, b";
36//!
37//! let ast = Parser::parse_sql(&dialect, sql).unwrap();
38//!
39//! println!("AST: {:?}", ast);
40//! ```
41//!
42//! [sqlparser crates.io page]: https://crates.io/crates/sqlparser
43//! [`Parser::parse_sql`]: crate::parser::Parser::parse_sql
44//! [`Parser::new`]: crate::parser::Parser::new
45//! [`AST`]: crate::ast
46//! [`ast`]: crate::ast
47//! [`Dialect`]: crate::dialect::Dialect
48
49#![cfg_attr(not(feature = "std"), no_std)]
50#![allow(clippy::upper_case_acronyms)]
51
52// Allow proc-macros to find this crate
53extern crate self as sqlparser;
54
55#[cfg(not(feature = "std"))]
56extern crate alloc;
57
58#[macro_use]
59#[cfg(test)]
60extern crate pretty_assertions;
61
62pub mod ast;
63#[macro_use]
64pub mod dialect;
65pub mod keywords;
66pub mod parser;
67pub mod tokenizer;
68
69#[doc(hidden)]
70// This is required to make utilities accessible by both the crate-internal
71// unit-tests and by the integration tests <https://stackoverflow.com/a/44541071/1026>
72// External users are not supposed to rely on this module.
73pub mod test_utils;