oxide_sql_core/parser/mod.rs
1//! SQL Parser
2//!
3//! A hand-written recursive descent parser with Pratt expression
4//! parsing for a subset of SQL:2016 (ISO/IEC 9075) covering DML/DQL
5//! operations.
6//!
7//! # Parsing approach
8//!
9//! Statements (`SELECT`, `INSERT`, `UPDATE`, `DELETE`) are parsed by
10//! dedicated recursive-descent methods. Expressions use a Pratt
11//! (top-down operator precedence) parser that handles prefix, infix,
12//! and postfix operators with correct precedence and associativity.
13//!
14//! # Supported statements
15//!
16//! | Statement | Notes |
17//! |-----------|-------|
18//! | `SELECT` | Full DQL with all clauses listed below |
19//! | `INSERT` | `VALUES`, `DEFAULT VALUES`, sub-`SELECT`, `ON CONFLICT` |
20//! | `UPDATE` | `SET`, optional `FROM`, optional alias |
21//! | `DELETE` | Optional alias, `WHERE` |
22//!
23//! # SELECT clauses
24//!
25//! `DISTINCT` / `ALL`, column list with aliases, `FROM` (table,
26//! schema-qualified table, subquery, aliases), `WHERE`, `GROUP BY`,
27//! `HAVING`, `ORDER BY` (with `ASC` / `DESC` and
28//! `NULLS FIRST` / `NULLS LAST`), `LIMIT`, `OFFSET`.
29//!
30//! # JOINs
31//!
32//! `INNER`, `LEFT [OUTER]`, `RIGHT [OUTER]`, `FULL [OUTER]`,
33//! `CROSS`, with `ON` or `USING` conditions. Chained (multi-table)
34//! joins are left-associative.
35//!
36//! # Expressions
37//!
38//! - **Literals**: integers, floats, strings, blobs (`X'…'`),
39//! booleans (`TRUE`/`FALSE`), `NULL`
40//! - **Column references**: unqualified (`col`), qualified (`t.col`),
41//! wildcards (`*`, `t.*`)
42//! - **Binary operators**: `+`, `-`, `*`, `/`, `%`, `||`, `&`, `|`,
43//! `<<`, `>>`, `=`, `!=`/`<>`, `<`, `<=`, `>`, `>=`, `AND`, `OR`,
44//! `LIKE`
45//! - **Unary operators**: `-` (negate), `NOT`, `~` (bitwise NOT)
46//! - **Special forms**: `IS [NOT] NULL`, `BETWEEN … AND …`,
47//! `IN (…)`, `CASE`/`WHEN`/`THEN`/`ELSE`/`END`,
48//! `CAST(… AS <type>)`, `EXISTS(…)`
49//! - **Function calls**: named functions with optional `DISTINCT`
50//! (e.g. `COUNT(DISTINCT col)`)
51//! - **Subqueries**: scalar `(SELECT …)` in expressions
52//! - **Parameters**: positional (`?`) and named (`:name`)
53//!
54//! # Data types (via CAST)
55//!
56//! `SMALLINT`, `INTEGER`/`INT`, `BIGINT`, `REAL`, `DOUBLE`/`FLOAT`,
57//! `DECIMAL(p, s)`, `NUMERIC(p, s)`, `CHAR(n)`, `VARCHAR(n)`,
58//! `TEXT`, `BLOB`, `BINARY(n)`, `VARBINARY(n)`, `DATE`, `TIME`,
59//! `TIMESTAMP`, `DATETIME`, `BOOLEAN`.
60//!
61//! # INSERT extensions
62//!
63//! `ON CONFLICT DO NOTHING` and `ON CONFLICT DO UPDATE SET …` for
64//! upsert semantics.
65//!
66//! # Not supported
67//!
68//! DDL (`CREATE` / `ALTER` / `DROP`), transactions
69//! (`BEGIN` / `COMMIT` / `ROLLBACK`), set operations
70//! (`UNION` / `INTERSECT` / `EXCEPT`), window functions
71//! (`OVER` / `PARTITION BY`), common table expressions (`WITH`),
72//! `NATURAL JOIN`.
73
74mod core;
75mod error;
76mod pratt;
77
78pub use core::Parser;
79pub use error::ParseError;