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
Split clauses into two groups: multiline & single line #483
Conversation
For start, use it for SET SCHEMA clause
Instead use 3 separate methods for the 3 styles of clause formatting
- row access policy - capacity - assignment - reservation
…to oneline-clauses
|
||
// Contains the same data as DialectFormatOptions, | ||
// but optimized for faster and more conventient lookup. | ||
export interface ProcessedDialectFormatOptions { |
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.
can we not just use this as the default interface for DialectFormatOptions and add a wrapper function to transform the string[] into Record ?
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.
It's not only the onlineClauses
field that differs. It's also the alwaysDenseOperators
field which is originally optional, but then processed to be empty array if missing.
// but optimized for faster and more conventient lookup. | ||
export interface ProcessedDialectFormatOptions { | ||
alwaysDenseOperators: string[]; | ||
onelineClauses: Record<string, boolean>; |
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.
can be
onelineClauses: Record<string, boolean>; | |
onelineClauses: Record<string, true>; |
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.
Tried that, but in this case TypeScript thinks that onlineClauses[anything]
always evaluates to true.
So far pretty much all SQL clauses have been formatted like so:
However, for many clauses this is not really how one would normally format SQL. For example, one rarely formats SQL like so:
Rather one would format this on a single line:
This change makes it so, that by default all clauses get formatted in the latter way. i.e. all clauses for which we don't have specific tests as to how we'd want them to be formatted. Most dialects have this sort of kitchen-sink list of clauses that's just been copied there from documentation. So these are all now being formatted in this one-line style. This will also aligns more with how the default
sql
-dialect formatter handles unknown SQL syntax.Also hand-picked a few clauses for which I wanted to intentionally apply this style:
TRUNCATE TABLE
SET SCHEMA
ALTER TABLE
DROP TABLE
DELETE FROM
UPDATE
As a bonus, this also: