-
Notifications
You must be signed in to change notification settings - Fork 605
Support DROP [TABLE|VIEW] #75
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
Conversation
Pull Request Test Coverage Report for Build 203
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this adds support for parsing DROP { TABLE | VIEW } [ IF EXISTS ] <object_name>[, <object_name>...] [ { CASCADE | RESTRICT } ]
, where
CASCADE
/RESTRICT
is standard (the default, when omitted, isRESTRICT
)IF EXISTS
and multiple object names in one statement are non-standard, but are supported in various DBs (e.g. Postgresql, MSSQL)
I had a less complete implementation in andygrove@1021d39 - which I'll remove. I had one variant in SQLStatement
(SQLDrop
) with the object type (TABLE or VIEW) stored in a field. Given that the majority of DROP statements in the spec are defined as either DROP <OBJECT_TYPE> <drop behavior>
or simply DROP <OBJECT_TYPE>
, perhaps it would be simpler to do it like I did? That way you wouldn't need the "_internal"/"_inner" methods.
Please run cargo fmt
if you choose to update the PR.
(Also note that this has a (trivial) conflict with #74)
src/sqlast/mod.rs
Outdated
"DROP {}{} {}{}{}", | ||
object_type, | ||
if self.if_exists { " IF EXISTS" } else { "" }, | ||
self.names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma_separated_string(&self.names),
seems to work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Done.
src/sqlast/mod.rs
Outdated
pub if_exists: bool, | ||
pub names: Vec<SQLObjectName>, | ||
pub cascade: bool, | ||
pub restrict: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with SELECT ALL
(#76) I wonder if it makes sense to store the restrict
in the AST, given it's the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this adds support for parsing
DROP { TABLE | VIEW } [ IF EXISTS ] <object_name>[, <object_name>...] [ { CASCADE | RESTRICT } ]
, where
CASCADE
/RESTRICT
is standard (the default, when omitted, isRESTRICT
)IF EXISTS
and multiple object names in one statement are non-standard, but are supported in various DBs (e.g. Postgresql, MSSQL)
Yes, that's exactly right.
I had a less complete implementation in 1021d39 - which I'll remove. I had one variant in
SQLStatement
(SQLDrop
) with the object type (TABLE or VIEW) stored in a field. Given that the majority of DROP statements in the spec are defined as eitherDROP <OBJECT_TYPE> <drop behavior>
or simplyDROP <OBJECT_TYPE>
, perhaps it would be simpler to do it like I did? That way you wouldn't need the "_internal"/"_inner" methods.
Oh, interesting. We didn't notice that before writing this implementation. Definitely not opposed to having SQLDrop store the object type (table/view), rather than vice-versa, though I'd prefer to have a proper enum rather than a string type, so that it's possible to exhaustively handle all the cases. Thoughts?
Please run
cargo fmt
if you choose to update the PR.
Done.
Co-authored-by: Jamie Brandon <[email protected]>
I decided I like this a lot, and adjusted the PR accordingly. |
Great, thanks! I've asked @andygrove if he wants to take a look at this and 72, 73, 76 before merging. I hope to get to the other PRs "soon":) |
No description provided.