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//! See [`Parser::parse_sql`](crate::parser::Parser::parse_sql) and
20//! [`Parser::new`](crate::parser::Parser::new) for the Parsing API
21//! and the [`ast`](crate::ast) crate for the AST structure.
22//!
23//! Example:
24//!
25//! ```
26//! use sqlparser::dialect::GenericDialect;
27//! use sqlparser::parser::Parser;
28//!
29//! let dialect = GenericDialect {}; // or AnsiDialect
30//!
31//! let sql = "SELECT a, b, 123, myfunc(b) \
32//! FROM table_1 \
33//! WHERE a > b AND b < 100 \
34//! ORDER BY a DESC, b";
35//!
36//! let ast = Parser::parse_sql(&dialect, sql).unwrap();
37//!
38//! println!("AST: {:?}", ast);
39//! ```
40//! [sqlparser crates.io page]: https://crates.io/crates/sqlparser
41
42#![cfg_attr(not(feature = "std"), no_std)]
43#![allow(clippy::upper_case_acronyms)]
44
45// Allow proc-macros to find this crate
46extern crate self as sqlparser;
47
48#[cfg(not(feature = "std"))]
49extern crate alloc;
50
51#[macro_use]
52#[cfg(test)]
53extern crate pretty_assertions;
54
55pub mod ast;
56#[macro_use]
57pub mod dialect;
58pub mod keywords;
59pub mod parser;
60pub mod tokenizer;
61
62#[doc(hidden)]
63// This is required to make utilities accessible by both the crate-internal
64// unit-tests and by the integration tests <https://stackoverflow.com/a/44541071/1026>
65// External users are not supposed to rely on this module.
66pub mod test_utils;