Skip to content

Commit 9cc4bc3

Browse files
committed
Adding rustdoc comments
1 parent ecc6b5f commit 9cc4bc3

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//! SQL Parser for Rust
16+
//!
17+
//! Example code:
18+
//!
19+
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parsed SQL into an Abstract
20+
//! Syntax Tree (AST).
21+
//!
22+
//! ```
23+
//! use sqlparser::sqlparser::Parser;
24+
//!
25+
//! let sql = "SELECT a, b, 123, myfunc(b) \
26+
//! FROM table_1 \
27+
//! WHERE a > b AND b < 100 \
28+
//! ORDER BY a DESC, b";
29+
//!
30+
//! let ast = Parser::parse_sql(sql.to_string()).unwrap();
31+
//!
32+
//! println!("AST: {:?}", ast);
33+
//! ```
34+
35+
1536
extern crate fnv;
1637

1738
#[macro_use]

src/sqlast.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,100 @@
1717
/// SQL Abstract Syntax Tree (AST)
1818
#[derive(Debug, Clone, PartialEq)]
1919
pub enum ASTNode {
20+
/// Identifier e.g. table name or column name
2021
SQLIdentifier(String),
22+
/// Wildcard e.g. `*`
2123
SQLWildcard,
24+
/// Multi part identifier e.g. `myschema.dbo.mytable`
2225
SQLCompoundIdentifier(Vec<String>),
26+
/// Assigment e.g. `name = 'Fred'` in an UPDATE statement
27+
SQLAssignment(String, Box<ASTNode>),
28+
/// `IS NULL` expression
2329
SQLIsNull(Box<ASTNode>),
30+
/// `IS NOT NULL` expression
2431
SQLIsNotNull(Box<ASTNode>),
32+
/// Binary expression e.g. `1 + 1` or `foo > bar`
2533
SQLBinaryExpr {
2634
left: Box<ASTNode>,
2735
op: SQLOperator,
2836
right: Box<ASTNode>,
2937
},
38+
/// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
3039
SQLCast {
3140
expr: Box<ASTNode>,
3241
data_type: SQLType,
3342
},
43+
/// Nested expression e.g. `(foo > bar)` or `(1)`
3444
SQLNested(Box<ASTNode>),
45+
/// Unary expression
3546
SQLUnary {
3647
operator: SQLOperator,
3748
rex: Box<ASTNode>,
3849
},
50+
/// Literal signed long
3951
SQLLiteralLong(i64),
52+
/// Literal floating point value
4053
SQLLiteralDouble(f64),
54+
/// Literal string
4155
SQLLiteralString(String),
56+
/// Scalar function call e.g. `LEFT(foo, 5)`
4257
SQLFunction {
4358
id: String,
4459
args: Vec<ASTNode>,
4560
},
61+
/// Expression with ASC/DESC attribute e.g. `foo ASC` or `foo DESC`.=
4662
SQLOrderBy {
4763
expr: Box<ASTNode>,
4864
asc: bool,
4965
},
66+
/// SELECT
5067
SQLSelect {
68+
/// projection expressions
5169
projection: Vec<ASTNode>,
70+
/// FROM
5271
relation: Option<Box<ASTNode>>,
72+
/// WHERE
5373
selection: Option<Box<ASTNode>>,
74+
/// ORDER BY
5475
order_by: Option<Vec<ASTNode>>,
76+
/// GROUP BY
5577
group_by: Option<Vec<ASTNode>>,
78+
/// HAVING
5679
having: Option<Box<ASTNode>>,
80+
/// LIMIT
5781
limit: Option<Box<ASTNode>>,
5882
},
83+
/// INSERT
84+
SQLInsert {
85+
/// TABLE
86+
table_name: String,
87+
/// COLUMNS
88+
columns: Vec<String>,
89+
/// VALUES (vector of rows to insert)
90+
values: Vec<Vec<ASTNode>>,
91+
},
92+
/// UPDATE
93+
SQLUpdate {
94+
/// TABLE
95+
table_name: String,
96+
/// Columns being assigned
97+
columns: Vec<String>,
98+
/// Values being assigned
99+
values: Vec<ASTNode>,
100+
/// WHERE
101+
selection: Option<Box<ASTNode>>,
102+
},
103+
/// DELETE
59104
SQLDelete {
60-
relation: Option<Box<ASTNode>>, // FROM statement
61-
selection: Option<Box<ASTNode>>, // WHERE statement
105+
/// FROM
106+
relation: Option<Box<ASTNode>>,
107+
/// WHERE
108+
selection: Option<Box<ASTNode>>,
109+
/// ORDER BY
62110
order_by: Option<Vec<ASTNode>>,
63111
limit: Option<Box<ASTNode>>,
64112
},
113+
/// CREATE TABLE
65114
SQLCreateTable {
66115
/// Table name
67116
name: String,

0 commit comments

Comments
 (0)