Skip to content

Commit

Permalink
Merge pull request #65 from cvng/fix/view-relpersistence
Browse files Browse the repository at this point in the history
feat: support "create view" with relpersistence
  • Loading branch information
psteinroe authored Dec 13, 2023
2 parents 447e429 + 4aeba6a commit 421e189
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::Or));
tokens.push(TokenProperty::from(Token::Replace));
}
if let Some(n) = &n.view {
match n.relpersistence.as_str() {
// Permanent
"p" => {},
// Unlogged
"u" => tokens.push(TokenProperty::from(Token::Unlogged)),
// Temporary
"t" => tokens.push(TokenProperty::from(Token::Temporary)),
_ => panic!("Unknown ViewStmt {:#?}", n),
}
}
},
"CreateStmt" => quote! {
tokens.push(TokenProperty::from(Token::Create));
Expand Down
16 changes: 16 additions & 0 deletions crates/parser/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,20 @@ mod tests {
],
)
}

#[test]
fn test_create_view() {
test_get_node_properties(
"create or replace temporary view comedies as select * from films;",
SyntaxKind::ViewStmt,
vec![
TokenProperty::from(SyntaxKind::Create),
TokenProperty::from(SyntaxKind::View),
TokenProperty::from(SyntaxKind::As),
TokenProperty::from(SyntaxKind::Or),
TokenProperty::from(SyntaxKind::Replace),
TokenProperty::from(SyntaxKind::Temporary),
],
)
}
}

0 comments on commit 421e189

Please sign in to comment.