diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 1aa3c914..6d6db5d3 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -431,14 +431,14 @@ pub enum Expr { op: BinaryOperator, right: Box, }, - /// LIKE + /// `[NOT] LIKE [ESCAPE ]` Like { negated: bool, expr: Box, pattern: Box, escape_char: Option, }, - /// ILIKE (case-insensitive LIKE) + /// `ILIKE` (case-insensitive `LIKE`) ILike { negated: bool, expr: Box, @@ -460,13 +460,13 @@ pub enum Expr { // true for REGEXP, false for RLIKE (no difference in semantics) regexp: bool, }, - /// Any operation e.g. `foo > ANY(bar)`, comparison operator is one of [=, >, <, =>, =<, !=] + /// `ANY` operation e.g. `foo > ANY(bar)`, comparison operator is one of `[=, >, <, =>, =<, !=]` AnyOp { left: Box, compare_op: BinaryOperator, right: Box, }, - /// ALL operation e.g. `foo > ALL(bar)`, comparison operator is one of [=, >, <, =>, =<, !=] + /// `ALL` operation e.g. `foo > ALL(bar)`, comparison operator is one of `[=, >, <, =>, =<, !=]` AllOp { left: Box, compare_op: BinaryOperator, @@ -474,7 +474,7 @@ pub enum Expr { }, /// Unary operation e.g. `NOT foo` UnaryOp { op: UnaryOperator, expr: Box }, - /// CONVERT a value to a different data type or character encoding `CONVERT(foo USING utf8mb4)` + /// CONVERT a value to a different data type or character encoding. e.g. `CONVERT(foo USING utf8mb4)` Convert { /// The expression to convert expr: Box, @@ -485,7 +485,7 @@ pub enum Expr { /// whether the target comes before the expr (MSSQL syntax) target_before_value: bool, }, - /// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))` + /// `CAST` an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))` Cast { expr: Box, data_type: DataType, @@ -493,7 +493,7 @@ pub enum Expr { // https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#formatting_syntax format: Option, }, - /// TRY_CAST an expression to a different data type e.g. `TRY_CAST(foo AS VARCHAR(123))` + /// `TRY_CAST` an expression to a different data type e.g. `TRY_CAST(foo AS VARCHAR(123))` // this differs from CAST in the choice of how to implement invalid conversions TryCast { expr: Box, @@ -502,7 +502,7 @@ pub enum Expr { // https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#formatting_syntax format: Option, }, - /// SAFE_CAST an expression to a different data type e.g. `SAFE_CAST(foo AS FLOAT64)` + /// `SAFE_CAST` an expression to a different data type e.g. `SAFE_CAST(foo AS FLOAT64)` // only available for BigQuery: https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#safe_casting // this works the same as `TRY_CAST` SafeCast { @@ -517,6 +517,9 @@ pub enum Expr { timestamp: Box, time_zone: String, }, + /// Extract a field from a timestamp e.g. `EXTRACT(MONTH FROM foo)` + /// + /// Syntax: /// ```sql /// EXTRACT(DateTimeField FROM ) /// ``` @@ -665,8 +668,6 @@ pub enum Expr { /// = CompoundIdentifier /// = String literal /// ``` - /// - /// /// [(1)]: https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html#function_match MatchAgainst { /// `(, , ...)`. @@ -1375,6 +1376,9 @@ pub enum Password { visit(with = "visit_statement") )] pub enum Statement { + /// ```sql + /// ANALYZE + /// ``` /// Analyze (Hive) Analyze { #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] @@ -1386,6 +1390,9 @@ pub enum Statement { noscan: bool, compute_statistics: bool, }, + /// ```sql + /// TRUNCATE + /// ``` /// Truncate (Hive) Truncate { #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] @@ -1394,6 +1401,9 @@ pub enum Statement { /// TABLE - optional keyword; table: bool, }, + /// ```sql + /// MSCK + /// ``` /// Msck (Hive) Msck { #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] @@ -1401,9 +1411,13 @@ pub enum Statement { repair: bool, partition_action: Option, }, + /// ```sql /// SELECT + /// ``` Query(Box), + /// ```sql /// INSERT + /// ``` Insert { /// Only for Sqlite or: Option, @@ -1438,7 +1452,13 @@ pub enum Statement { file_format: Option, source: Box, }, + /// ```sql + /// CALL + /// ``` Call(Function), + /// ```sql + /// COPY [TO | FROM] ... + /// ``` Copy { /// The source of 'COPY TO', or the target of 'COPY FROM' source: CopySource, @@ -1473,12 +1493,17 @@ pub enum Statement { copy_options: DataLoadingOptions, validation_mode: Option, }, - /// Close - closes the portal underlying an open cursor. + /// ```sql + /// CLOSE + /// ``` + /// Closes the portal underlying an open cursor. Close { /// Cursor name cursor: CloseCursor, }, + /// ```sql /// UPDATE + /// ``` Update { /// TABLE table: TableWithJoins, @@ -1491,7 +1516,9 @@ pub enum Statement { /// RETURNING returning: Option>, }, + /// ```sql /// DELETE + /// ``` Delete { /// Multi tables delete are supported in mysql tables: Vec, @@ -1508,7 +1535,9 @@ pub enum Statement { /// LIMIT (MySQL) limit: Option, }, + /// ```sql /// CREATE VIEW + /// ``` CreateView { or_replace: bool, materialized: bool, @@ -1525,7 +1554,9 @@ pub enum Statement { /// if true, has SQLite `TEMP` or `TEMPORARY` clause temporary: bool, }, + /// ```sql /// CREATE TABLE + /// ``` CreateTable { or_replace: bool, temporary: bool, @@ -1567,7 +1598,10 @@ pub enum Statement { /// then strict typing rules apply to that table. strict: bool, }, - /// SQLite's `CREATE VIRTUAL TABLE .. USING ()` + /// ```sql + /// CREATE VIRTUAL TABLE .. USING ()` + /// ``` + /// Sqlite specific statement CreateVirtualTable { #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] name: ObjectName, @@ -1575,7 +1609,9 @@ pub enum Statement { module_name: Ident, module_args: Vec, }, - /// CREATE INDEX + /// ```sql + /// `CREATE INDEX` + /// ``` CreateIndex { /// index name name: Option, @@ -1590,7 +1626,9 @@ pub enum Statement { nulls_distinct: Option, predicate: Option, }, + /// ```sql /// CREATE ROLE + /// ``` /// See [postgres](https://www.postgresql.org/docs/current/sql-createrole.html) CreateRole { names: Vec, @@ -1614,7 +1652,9 @@ pub enum Statement { // MSSQL authorization_owner: Option, }, + /// ```sql /// ALTER TABLE + /// ``` AlterTable { /// Table name #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] @@ -1623,11 +1663,16 @@ pub enum Statement { only: bool, operations: Vec, }, + /// ```sql + /// ALTER INDEX + /// ``` AlterIndex { name: ObjectName, operation: AlterIndexOperation, }, + /// ```sql /// ALTER VIEW + /// ``` AlterView { /// View name #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] @@ -1636,12 +1681,16 @@ pub enum Statement { query: Box, with_options: Vec, }, + /// ```sql /// ALTER ROLE + /// ``` AlterRole { name: Ident, operation: AlterRoleOperation, }, + /// ```sql /// ATTACH DATABASE 'path/to/file' AS alias + /// ``` /// (SQLite-specific) AttachDatabase { /// The name to bind to the newly attached database @@ -1651,7 +1700,9 @@ pub enum Statement { /// true if the syntax is 'ATTACH DATABASE', false if it's just 'ATTACH' database: bool, }, - /// DROP + /// ```sql + /// DROP [TABLE, VIEW, ...] + /// ``` Drop { /// The type of the object to drop: TABLE, VIEW, etc. object_type: ObjectType, @@ -1671,7 +1722,9 @@ pub enum Statement { /// MySQL-specific "TEMPORARY" keyword temporary: bool, }, - /// DROP Function + /// ```sql + /// DROP FUNCTION + /// ``` DropFunction { if_exists: bool, /// One or more function to drop @@ -1679,7 +1732,10 @@ pub enum Statement { /// `CASCADE` or `RESTRICT` option: Option, }, - /// DECLARE - Declaring Cursor Variables + /// ```sql + /// DECLARE + /// ``` + /// Declare Cursor Variables /// /// Note: this is a PostgreSQL-specific statement, /// but may also compatible with other SQL. @@ -1702,7 +1758,10 @@ pub enum Statement { hold: Option, query: Box, }, - /// FETCH - retrieve rows from a query using a cursor + /// ```sql + /// FETCH + /// ``` + /// Retrieve rows from a query using a cursor /// /// Note: this is a PostgreSQL-specific statement, /// but may also compatible with other SQL. @@ -1713,14 +1772,18 @@ pub enum Statement { /// Optional, It's possible to fetch rows form cursor to the table into: Option, }, + /// ```sql /// DISCARD [ ALL | PLANS | SEQUENCES | TEMPORARY | TEMP ] + /// ``` /// /// Note: this is a PostgreSQL-specific statement, /// but may also compatible with other SQL. - Discard { - object_type: DiscardObject, - }, - /// SET `[ SESSION | LOCAL ]` ROLE role_name. Examples: [ANSI][1], [Postgresql][2], [MySQL][3], and [Oracle][4]. + Discard { object_type: DiscardObject }, + /// ```sql + /// SET [ SESSION | LOCAL ] ROLE role_name + /// ``` + /// + /// Sets sesssion state. Examples: [ANSI][1], [Postgresql][2], [MySQL][3], and [Oracle][4] /// /// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#set-role-statement /// [2]: https://www.postgresql.org/docs/14/sql-set-role.html @@ -1751,36 +1814,35 @@ pub enum Statement { /// /// Note: this is a PostgreSQL-specific statements /// `SET TIME ZONE ` is an alias for `SET timezone TO ` in PostgreSQL - SetTimeZone { - local: bool, - value: Expr, - }, + SetTimeZone { local: bool, value: Expr }, + /// ```sql /// SET NAMES 'charset_name' [COLLATE 'collation_name'] + /// ``` /// /// Note: this is a MySQL-specific statement. SetNames { charset_name: String, collation_name: Option, }, + /// ```sql /// SET NAMES DEFAULT + /// ``` /// /// Note: this is a MySQL-specific statement. SetNamesDefault {}, - /// SHOW FUNCTIONS + /// `SHOW FUNCTIONS` /// /// Note: this is a Presto-specific statement. - ShowFunctions { - filter: Option, - }, + ShowFunctions { filter: Option }, /// ```sql /// SHOW /// ``` /// /// Note: this is a PostgreSQL-specific statement. - ShowVariable { - variable: Vec, - }, + ShowVariable { variable: Vec }, + /// ```sql /// SHOW VARIABLES + /// ``` /// /// Note: this is a MySQL-specific statement. ShowVariables { @@ -1788,14 +1850,18 @@ pub enum Statement { global: bool, session: bool, }, + /// ```sql /// SHOW CREATE TABLE + /// ``` /// /// Note: this is a MySQL-specific statement. ShowCreate { obj_type: ShowCreateObject, obj_name: ObjectName, }, + /// ```sql /// SHOW COLUMNS + /// ``` /// /// Note: this is a MySQL-specific statement. ShowColumns { @@ -1805,8 +1871,9 @@ pub enum Statement { table_name: ObjectName, filter: Option, }, + /// ```sql /// SHOW TABLES - /// + /// ``` /// Note: this is a MySQL-specific statement. ShowTables { extended: bool, @@ -1814,34 +1881,42 @@ pub enum Statement { db_name: Option, filter: Option, }, + /// ```sql /// SHOW COLLATION + /// ``` /// /// Note: this is a MySQL-specific statement. - ShowCollation { - filter: Option, - }, + ShowCollation { filter: Option }, + /// ```sql /// USE + /// ``` /// /// Note: This is a MySQL-specific statement. - Use { - db_name: Ident, - }, - /// `START [ TRANSACTION | WORK ] | START TRANSACTION } ...` + Use { db_name: Ident }, + /// ```sql + /// START [ TRANSACTION | WORK ] | START TRANSACTION } ... + /// ``` /// If `begin` is false. /// + /// ```sql /// `BEGIN [ TRANSACTION | WORK ] | START TRANSACTION } ...` + /// ``` /// If `begin` is true StartTransaction { modes: Vec, begin: bool, }, - /// `SET TRANSACTION ...` + /// ```sql + /// SET TRANSACTION ... + /// ``` SetTransaction { modes: Vec, snapshot: Option, session: bool, }, - /// `COMMENT ON ...` + /// ```sql + /// COMMENT ON ... + /// ``` /// /// Note: this is a PostgreSQL-specific statement. Comment { @@ -1852,22 +1927,28 @@ pub enum Statement { /// See if_exists: bool, }, - /// `COMMIT [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]` - Commit { - chain: bool, - }, - /// `ROLLBACK [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ] [ TO [ SAVEPOINT ] savepoint_name ]` + /// ```sql + /// COMMIT [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ] + /// ``` + Commit { chain: bool }, + /// ```sql + /// ROLLBACK [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ] [ TO [ SAVEPOINT ] savepoint_name ] + /// ``` Rollback { chain: bool, savepoint: Option, }, + /// ```sql /// CREATE SCHEMA + /// ``` CreateSchema { /// ` | AUTHORIZATION | AUTHORIZATION ` schema_name: SchemaName, if_not_exists: bool, }, + /// ```sql /// CREATE DATABASE + /// ``` CreateDatabase { db_name: ObjectName, if_not_exists: bool, @@ -1927,12 +2008,16 @@ pub enum Statement { copy_options: DataLoadingOptions, comment: Option, }, - /// `ASSERT [AS ]` + /// ```sql + /// ASSERT [AS ] + /// ``` Assert { condition: Expr, message: Option, }, + /// ```sql /// GRANT privileges ON objects TO grantees + /// ``` Grant { privileges: Privileges, objects: GrantObjects, @@ -1940,7 +2025,9 @@ pub enum Statement { with_grant_option: bool, granted_by: Option, }, + /// ```sql /// REVOKE privileges ON objects FROM grantees + /// ``` Revoke { privileges: Privileges, objects: GrantObjects, @@ -1948,21 +2035,21 @@ pub enum Statement { granted_by: Option, cascade: bool, }, - /// `DEALLOCATE [ PREPARE ] { name | ALL }` + /// ```sql + /// DEALLOCATE [ PREPARE ] { name | ALL } + /// ``` /// /// Note: this is a PostgreSQL-specific statement. - Deallocate { - name: Ident, - prepare: bool, - }, - /// `EXECUTE name [ ( parameter [, ...] ) ]` + Deallocate { name: Ident, prepare: bool }, + /// ```sql + /// EXECUTE name [ ( parameter [, ...] ) ] + /// ``` /// /// Note: this is a PostgreSQL-specific statement. - Execute { - name: Ident, - parameters: Vec, - }, - /// `PREPARE name [ ( data_type [, ...] ) ] AS statement` + Execute { name: Ident, parameters: Vec }, + /// ```sql + /// PREPARE name [ ( data_type [, ...] ) ] AS statement + /// ``` /// /// Note: this is a PostgreSQL-specific statement. Prepare { @@ -1970,7 +2057,9 @@ pub enum Statement { data_types: Vec, statement: Box, }, + /// ```sql /// KILL [CONNECTION | QUERY | MUTATION] + /// ``` /// /// See /// See @@ -1979,7 +2068,9 @@ pub enum Statement { // processlist_id id: u64, }, + /// ```sql /// EXPLAIN TABLE + /// ``` /// Note: this is a MySQL-specific statement. See ExplainTable { /// If true, query used the MySQL `DESCRIBE` alias for explain @@ -1988,7 +2079,9 @@ pub enum Statement { #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] table_name: ObjectName, }, - /// EXPLAIN / DESCRIBE for select_statement + /// ```sql + /// [EXPLAIN | DESCRIBE