Add DROP TABLE and CREATE TABLE (DDL) formatting#13
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class formatting support for basic DDL statements (DROP TABLE, CREATE TABLE with column definitions) so they no longer fall back to normalized-text passthrough, and fixes single-column INSERT column-list rendering to stay inline.
Changes:
- Add
SqlBeautifier::DropTableandSqlBeautifier::CreateTableparsers/renderers and integrate them intoFormatter. - Centralize CREATE TABLE modifier keywords in
Constants::TABLE_MODIFIERS(shared byCreateTableAsandCreateTable). - Fix
InsertQuery#render_column_listto render single-column lists inline and expand tests/docs accordingly.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/sql_beautifier/insert_query.spec.rb | Adds coverage for inline single-column INSERT column lists and updates existing expectations. |
| spec/sql_beautifier/formatter.spec.rb | Integration coverage for DROP TABLE / CREATE TABLE and single-column INSERT through the main formatter. |
| spec/sql_beautifier/drop_table.spec.rb | New unit specs for DROP TABLE parsing/rendering and configuration interactions. |
| spec/sql_beautifier/create_table.spec.rb | New unit specs for CREATE TABLE (DDL) parsing/rendering and configuration interactions. |
| spec/sql_beautifier.spec.rb | Verifies multi-statement formatting across DROP/CREATE/INSERT sequences. |
| spec/readme.spec.rb | Adds/updates README example expectations, including new DDL examples. |
| lib/sql_beautifier/insert_query.rb | Implements inline rendering for single-column column lists. |
| lib/sql_beautifier/formatter.rb | Routes DROP TABLE and CREATE TABLE statements to their new formatters. |
| lib/sql_beautifier/drop_table.rb | Introduces DROP TABLE parser/renderer. |
| lib/sql_beautifier/create_table_as.rb | Switches modifier detection to shared Constants::TABLE_MODIFIERS. |
| lib/sql_beautifier/create_table.rb | Introduces CREATE TABLE (DDL) parser/renderer for column-definition form. |
| lib/sql_beautifier/constants.rb | Adds TABLE_MODIFIERS shared constant. |
| lib/sql_beautifier.rb | Requires the new DropTable/CreateTable implementations. |
| README.md | Documents new DROP TABLE / CREATE TABLE formatting support with examples. |
| CHANGELOG.md | Records the new DDL formatting support and the INSERT single-column rendering fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR serves to add formatting support for
DROP TABLEandCREATE TABLEDDL statements, and fix single-column INSERT rendering.Previously,
DROP TABLEandCREATE TABLE(with column definitions) statements were not recognized by any parser and fell through to the normalized-text passthrough. They now get proper keyword casing and PascalCase table names, consistent with the rest of the formatter.The
CREATE TABLEparser supports modifiers (TEMP,TEMPORARY,UNLOGGED,LOCAL) andIF NOT EXISTS, preserving column definitions as-is. The modifier constant previously defined inCreateTableAshas been extracted toConstants::TABLE_MODIFIERSso both parsers can share it.A small fix to
InsertQuery#render_column_listensures single-column lists render inline (e.g.,insert into Table (id)) instead of expanding to three lines.