Skip to content

Commit 8909e7e

Browse files
committed
feat: support CreatedbStmt
1 parent 7e58c4d commit 8909e7e

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
@@ -668,6 +668,21 @@ fn custom_handlers(node: &Node) -> TokenStream {
668668
_ => panic!("Unknown IndexElem {:#?}", n.nulls_ordering()),
669669
}
670670
},
671+
"CreatedbStmt" => quote! {
672+
tokens.push(TokenProperty::from(Token::Create));
673+
tokens.push(TokenProperty::from(Token::Database));
674+
for option in &n.options {
675+
if let Some(NodeEnum::DefElem(node)) = &option.node {
676+
if node.defname == "location" {
677+
tokens.push(TokenProperty::from(Token::Default));
678+
}
679+
if node.defname == "connection_limit" {
680+
tokens.push(TokenProperty::from(Token::Limit));
681+
tokens.push(TokenProperty::from(Token::Iconst));
682+
}
683+
}
684+
}
685+
},
671686
_ => quote! {},
672687
}
673688
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,19 @@ mod tests {
239239
],
240240
)
241241
}
242+
243+
#[test]
244+
fn test_create_database() {
245+
test_get_node_properties(
246+
"create database x owner abc connection limit 5;",
247+
SyntaxKind::CreatedbStmt,
248+
vec![
249+
TokenProperty::from(SyntaxKind::Create),
250+
TokenProperty::from(SyntaxKind::Database),
251+
TokenProperty::from(SyntaxKind::Limit),
252+
TokenProperty::from(SyntaxKind::Iconst),
253+
TokenProperty::from("x".to_string()),
254+
],
255+
)
256+
}
242257
}

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)