Skip to content

feat: support multiple statements #58

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 21, 2018

Conversation

rafaelrpinto
Copy link
Contributor

@rafaelrpinto rafaelrpinto commented Dec 20, 2018

This PR attempts to improve formatting of multiple statement SQLs like it was discussed in here: #50

Basically we keep the semicolon formatting as is unless its followed by one or more line breaks and have another statement after it. In that case we preserve one line break between the statements.

I think this allows some formatting of multiple statements without interfering with the existing behaviour.

@coveralls
Copy link

coveralls commented Dec 20, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 9ecd1b0 on rafaelrpinto:master into 0c81168 on zeroturnaround:master.

@nene
Copy link
Collaborator

nene commented Dec 20, 2018

Hi @rafaelrpinto, thanks for a patch! Proper multiple-query support is something we definitely need.

It's nice that you have thought about potential backwards-compatibility issues. But I think we're better off not preserving the current (buggy) formatting of semicolons. Unless the whitespace in input SQL is somehow significant, it should not effect the output. Breaking up a chain of SQL statements on a single line is something one would expect a formatter to do.

Would you be interested in changing this pull request so that END_STATEMENT = ';' ?

Also, I suggest we rename END_STATEMENT token to QUERY_SEPARATOR.

@nene
Copy link
Collaborator

nene commented Dec 20, 2018

PS. Also, it looks that your git config is missing author name. I see:

Author: yourname <[email protected]>

@rafaelrpinto
Copy link
Contributor Author

@nene
Thanks for the heads-up on the git config 👍

Since we will simply consider the semicolon as line break always I rolled back most of the changes and took a simplified approach without creating any token types.

Please let me know if that was what you had in mind.

Thanks.

@nene
Copy link
Collaborator

nene commented Dec 21, 2018

Thanks. Look great! I'll merge this and hopefully will also release soonish (I'd like to also eliminate a security alert I'm getting because of an outdated dev-dependency).

@nene nene merged commit 15e1188 into sql-formatter-org:master Dec 21, 2018
@osv
Copy link
Contributor

osv commented Mar 21, 2019

Bump for release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants