Skip to content

feat: add support for create database #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(n));
},
"DefElem" => quote! {
match n.defname.as_str() {
"location" => {
tokens.push(TokenProperty::from(Token::Default));
},
"connection_limit" => {
tokens.push(TokenProperty::from(Token::Limit));
tokens.push(TokenProperty::from(Token::Iconst));
},
"owner" => {
tokens.push(TokenProperty::from(Token::Owner));
}
_ => {}
}
match n.defaction() {
protobuf::DefElemAction::DefelemUnspec => tokens.push(TokenProperty::from(Token::Ascii61)),
_ => panic!("Unknown DefElem {:#?}", n.defaction()),
Expand Down Expand Up @@ -679,10 +692,14 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::With));
}
},
"CompositeTypeStmt" => quote! {
"CompositeTypeStmt" => quote! {
tokens.push(TokenProperty::from(Token::Create));
tokens.push(TokenProperty::from(Token::TypeP));
},
"CreatedbStmt" => quote! {
tokens.push(TokenProperty::from(Token::Create));
tokens.push(TokenProperty::from(Token::Database));
},
_ => quote! {},
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/parser/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,17 @@ mod tests {
],
)
}

#[test]
fn test_create_database() {
test_get_node_properties(
"create database x owner abc connection limit 5;",
SyntaxKind::CreatedbStmt,
vec![
TokenProperty::from(SyntaxKind::Create),
TokenProperty::from(SyntaxKind::Database),
TokenProperty::from("x".to_string()),
],
)
}
}
6 changes: 6 additions & 0 deletions crates/parser/tests/data/statements/valid/0047.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE DATABASE x OWNER abc CONNECTION LIMIT 5;
CREATE DATABASE x ENCODING "SQL_ASCII";
CREATE DATABASE x LC_COLLATE "en_US.UTF-8";
CREATE DATABASE x LOCATION DEFAULT;
CREATE DATABASE x TABLESPACE abc;
CREATE DATABASE x TEMPLATE TRUE;
86 changes: 86 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: CREATE DATABASE x OWNER abc CONNECTION LIMIT 5;
---
Parse {
cst: [email protected]
[email protected]
[email protected] "CREATE"
[email protected] " "
[email protected] "DATABASE"
[email protected] " "
[email protected] "x"
[email protected] " "
[email protected]
[email protected] "OWNER"
[email protected] " "
[email protected] "abc"
[email protected] " "
[email protected]
[email protected] "CONNECTION"
[email protected] " "
[email protected] "LIMIT"
[email protected] " "
[email protected] "5"
[email protected] ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreatedbStmt(
CreatedbStmt {
dbname: "x",
options: [
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "owner",
arg: Some(
Node {
node: Some(
String(
String {
sval: "abc",
},
),
),
},
),
defaction: DefelemUnspec,
location: 18,
},
),
),
},
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "connection_limit",
arg: Some(
Node {
node: Some(
Integer(
Integer {
ival: 5,
},
),
),
},
),
defaction: DefelemUnspec,
location: 28,
},
),
),
},
],
},
),
range: 0..46,
},
],
}
57 changes: 57 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "\nCREATE DATABASE x ENCODING \"SQL_ASCII\";"
---
Parse {
cst: [email protected]
[email protected] "\n"
[email protected]
[email protected] "CREATE"
[email protected] " "
[email protected] "DATABASE"
[email protected] " "
[email protected] "x"
[email protected] " "
[email protected]
[email protected] "ENCODING"
[email protected] " "
[email protected] "\"SQL_ASCII\""
[email protected] ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreatedbStmt(
CreatedbStmt {
dbname: "x",
options: [
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "encoding",
arg: Some(
Node {
node: Some(
String(
String {
sval: "SQL_ASCII",
},
),
),
},
),
defaction: DefelemUnspec,
location: 18,
},
),
),
},
],
},
),
range: 0..39,
},
],
}
57 changes: 57 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "\nCREATE DATABASE x LC_COLLATE \"en_US.UTF-8\";"
---
Parse {
cst: [email protected]
[email protected] "\n"
[email protected]
[email protected] "CREATE"
[email protected] " "
[email protected] "DATABASE"
[email protected] " "
[email protected] "x"
[email protected] " "
[email protected]
[email protected] "LC_COLLATE"
[email protected] " "
[email protected] "\"en_US.UTF-8\""
[email protected] ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreatedbStmt(
CreatedbStmt {
dbname: "x",
options: [
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "lc_collate",
arg: Some(
Node {
node: Some(
String(
String {
sval: "en_US.UTF-8",
},
),
),
},
),
defaction: DefelemUnspec,
location: 18,
},
),
),
},
],
},
),
range: 0..43,
},
],
}
47 changes: 47 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "\nCREATE DATABASE x LOCATION DEFAULT;"
---
Parse {
cst: [email protected]
[email protected] "\n"
[email protected]
[email protected] "CREATE"
[email protected] " "
[email protected] "DATABASE"
[email protected] " "
[email protected] "x"
[email protected] " "
[email protected]
[email protected] "LOCATION"
[email protected] " "
[email protected] "DEFAULT"
[email protected] ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreatedbStmt(
CreatedbStmt {
dbname: "x",
options: [
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "location",
arg: None,
defaction: DefelemUnspec,
location: 18,
},
),
),
},
],
},
),
range: 0..35,
},
],
}
57 changes: 57 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "\nCREATE DATABASE x TABLESPACE abc;"
---
Parse {
cst: [email protected]
[email protected] "\n"
[email protected]
[email protected] "CREATE"
[email protected] " "
[email protected] "DATABASE"
[email protected] " "
[email protected] "x"
[email protected] " "
[email protected]
[email protected] "TABLESPACE"
[email protected] " "
[email protected] "abc"
[email protected] ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreatedbStmt(
CreatedbStmt {
dbname: "x",
options: [
Node {
node: Some(
DefElem(
DefElem {
defnamespace: "",
defname: "tablespace",
arg: Some(
Node {
node: Some(
String(
String {
sval: "abc",
},
),
),
},
),
defaction: DefelemUnspec,
location: 18,
},
),
),
},
],
},
),
range: 0..33,
},
],
}
Loading