Skip to content

Commit 0525ffb

Browse files
committed
feat: support CreatedbStmt
1 parent a1ebe78 commit 0525ffb

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Diff for: crates/codegen/src/get_node_properties.rs

+15
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,21 @@ fn custom_handlers(node: &Node) -> TokenStream {
664664
_ => panic!("Unknown IndexElem {:#?}", n.nulls_ordering()),
665665
}
666666
},
667+
"CreatedbStmt" => quote! {
668+
tokens.push(TokenProperty::from(Token::Create));
669+
tokens.push(TokenProperty::from(Token::Database));
670+
for option in &n.options {
671+
if let Some(NodeEnum::DefElem(node)) = &option.node {
672+
if node.defname == "location" {
673+
tokens.push(TokenProperty::from(Token::Default));
674+
}
675+
if node.defname == "connection_limit" {
676+
tokens.push(TokenProperty::from(Token::Limit));
677+
tokens.push(TokenProperty::from(Token::Iconst));
678+
}
679+
}
680+
}
681+
},
667682
_ => quote! {},
668683
}
669684
}

Diff for: crates/parser/src/codegen.rs

+15
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,19 @@ mod tests {
224224
],
225225
)
226226
}
227+
228+
#[test]
229+
fn test_create_database() {
230+
test_get_node_properties(
231+
"create database x owner abc connection limit 5;",
232+
SyntaxKind::CreatedbStmt,
233+
vec![
234+
TokenProperty::from(SyntaxKind::Create),
235+
TokenProperty::from(SyntaxKind::Database),
236+
TokenProperty::from(SyntaxKind::Limit),
237+
TokenProperty::from(SyntaxKind::Iconst),
238+
TokenProperty::from("x".to_string()),
239+
],
240+
)
241+
}
227242
}

Diff for: crates/parser/tests/data/statements/valid/0047.sql

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE DATABASE x OWNER abc CONNECTION LIMIT 5;
2+
CREATE DATABASE x ENCODING \"SQL_ASCII\";
3+
CREATE DATABASE x LC_COLLATE \"en_US.UTF-8\";
4+
CREATE DATABASE x LOCATION DEFAULT;
5+
CREATE DATABASE x TABLESPACE abc;
6+
CREATE DATABASE x TEMPLATE TRUE;

0 commit comments

Comments
 (0)