Repository navigation
Place joins at the same indentation level as FROM - #89
Conversation
nene
left a comment
There was a problem hiding this comment.
Thanks. This looks pretty solid 👍
| it(`formats each SELECT clause with indented body when it doesn't fit on a single line`, async () => { | ||
| expect( | ||
| await pretty( | ||
| `SELECT very_long_col_name, another_long_col_name | ||
| FROM my_super_long_table_name | ||
| WHERE my_table_name.x > my_table_name.y | ||
| GROUP BY long_col, even_longer_col | ||
| HAVING foo > some_long_col_name | ||
| ORDER BY foo ASC, bar DESC NULLS FIRST | ||
| LIMIT 250 OFFSET 100000000 | ||
| `, | ||
| { printWidth: 25 }, | ||
| ), | ||
| ).toBe(dedent` | ||
| SELECT | ||
| very_long_col_name, | ||
| another_long_col_name | ||
| FROM | ||
| my_super_long_table_name | ||
| FROM my_super_long_table_name |
There was a problem hiding this comment.
I think it would be better to change this test so that it would use multiple tables in FROM clause. Like FROM one_long_table_name, another_long_table_name.
Then that would align with the description of the test and it would also match the SELECT clause behavior - there we also would run into the same problem when SELECT would only contain a single column.
But we should cover this single-long-table-name case with a separate test inside the from.test.ts file.
| describe("LATERAL", () => { | ||
| it(`formats LATERAL subquery`, () => { | ||
| testMysql(dedent` | ||
| it(`formats LATERAL subquery`, async () => { | ||
| await testMysql(dedent` |
| NATURAL LEFT JOIN inventory NOT INDEXED | ||
| client, | ||
| inventory | ||
| LEFT JOIN client_sale ON client_sale.client_id = client.id |
There was a problem hiding this comment.
Yeah, this is definitely an awkward case.
I guess that's more of a code which nobody really writes on practice... though I might be mistaken.
In any case it's definitely an edge-case which we don't need to worry too much about as long as the formatting is not completely horrible.
As discussed in #69, this places joins at the same indentation level as
FROM, instead of indenting the whole FROM clause body:A few related details:
FROM a, b) keep the existing indented list layout, as do FROM clauses that mix commas with joins. Otherwise, the tables after the first one would start at the beginning of the line.PIVOT,UNPIVOT,TABLESAMPLEandFOR SYSTEM_TIME AS OFare now indented under the table they modify, so they don't look like separate clauses.FROMnow starts on theFROMline, the same way a subquery in a join already does.The first commit adds missing
awaits to three tests infrom.test.ts, which were passing regardless of their result.