diff --git a/crates/codegen/src/get_node_properties.rs b/crates/codegen/src/get_node_properties.rs index 15a872de..ecd2ec29 100644 --- a/crates/codegen/src/get_node_properties.rs +++ b/crates/codegen/src/get_node_properties.rs @@ -700,6 +700,15 @@ fn custom_handlers(node: &Node) -> TokenStream { tokens.push(TokenProperty::from(Token::Create)); tokens.push(TokenProperty::from(Token::Database)); }, + "CreateExtensionStmt" => quote! { + tokens.push(TokenProperty::from(Token::Create)); + tokens.push(TokenProperty::from(Token::Extension)); + if n.if_not_exists { + tokens.push(TokenProperty::from(Token::IfP)); + tokens.push(TokenProperty::from(Token::Not)); + tokens.push(TokenProperty::from(Token::Exists)); + } + }, _ => quote! {}, } } diff --git a/crates/parser/src/codegen.rs b/crates/parser/src/codegen.rs index a4ee60b7..c4488bef 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -281,4 +281,20 @@ mod tests { ], ) } + + #[test] + fn test_create_extension() { + test_get_node_properties( + r#"create extension if not exists x cascade version "1.2" schema a;"#, + SyntaxKind::CreateExtensionStmt, + vec![ + TokenProperty::from(SyntaxKind::Create), + TokenProperty::from(SyntaxKind::Extension), + TokenProperty::from(SyntaxKind::IfP), + TokenProperty::from(SyntaxKind::Not), + TokenProperty::from(SyntaxKind::Exists), + TokenProperty::from("x".to_string()), + ], + ) + } } diff --git a/crates/parser/tests/data/statements/valid/0049.sql b/crates/parser/tests/data/statements/valid/0049.sql new file mode 100644 index 00000000..f6fb52c3 --- /dev/null +++ b/crates/parser/tests/data/statements/valid/0049.sql @@ -0,0 +1,2 @@ +CREATE EXTENSION x; +CREATE EXTENSION IF NOT EXISTS x CASCADE VERSION "1.2" SCHEMA a; diff --git a/crates/parser/tests/snapshots/statements/valid/0049@1.snap b/crates/parser/tests/snapshots/statements/valid/0049@1.snap new file mode 100644 index 00000000..79c95b41 --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0049@1.snap @@ -0,0 +1,28 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: CREATE EXTENSION x; +--- +Parse { + cst: SourceFile@0..19 + CreateExtensionStmt@0..19 + Create@0..6 "CREATE" + Whitespace@6..7 " " + Extension@7..16 "EXTENSION" + Whitespace@16..17 " " + Ident@17..18 "x" + Ascii59@18..19 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateExtensionStmt( + CreateExtensionStmt { + extname: "x", + if_not_exists: false, + options: [], + }, + ), + range: 0..18, + }, + ], +} diff --git a/crates/parser/tests/snapshots/statements/valid/0049@2.snap b/crates/parser/tests/snapshots/statements/valid/0049@2.snap new file mode 100644 index 00000000..fbe1867e --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0049@2.snap @@ -0,0 +1,118 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "\nCREATE EXTENSION IF NOT EXISTS x CASCADE VERSION \"1.2\" SCHEMA a;" +--- +Parse { + cst: SourceFile@0..65 + Newline@0..1 "\n" + CreateExtensionStmt@1..65 + Create@1..7 "CREATE" + Whitespace@7..8 " " + Extension@8..17 "EXTENSION" + Whitespace@17..18 " " + IfP@18..20 "IF" + Whitespace@20..21 " " + Not@21..24 "NOT" + Whitespace@24..25 " " + Exists@25..31 "EXISTS" + Whitespace@31..32 " " + Ident@32..33 "x" + Whitespace@33..34 " " + DefElem@34..41 + Cascade@34..41 "CASCADE" + Whitespace@41..42 " " + DefElem@42..55 + VersionP@42..49 "VERSION" + Whitespace@49..50 " " + Ident@50..55 "\"1.2\"" + Whitespace@55..56 " " + DefElem@56..64 + Schema@56..62 "SCHEMA" + Whitespace@62..63 " " + Ident@63..64 "a" + Ascii59@64..65 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateExtensionStmt( + CreateExtensionStmt { + extname: "x", + if_not_exists: true, + options: [ + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "cascade", + arg: Some( + Node { + node: Some( + Boolean( + Boolean { + boolval: true, + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 33, + }, + ), + ), + }, + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "new_version", + arg: Some( + Node { + node: Some( + String( + String { + sval: "1.2", + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 41, + }, + ), + ), + }, + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "schema", + arg: Some( + Node { + node: Some( + String( + String { + sval: "a", + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 55, + }, + ), + ), + }, + ], + }, + ), + range: 0..64, + }, + ], +}