@@ -69,10 +69,12 @@ Along with DAO changes, the plugin will refactor the SQL file directory and file
6969- After refactoring the DAO package, the SQL directory will also be updated.
7070![ RenameDao.gif] ( images/gif/RenameDao.gif )
7171
72- ## Formatter (Preview)
72+ ## Formatter
7373Provides code formatting for SQL syntax.
7474This feature is in preview. You cannot customize the indentation or keywords to be broken down!
7575
76+ The formatter works with both SQL files and SQL text blocks within ` @Sql ` annotations in DAO methods.
77+
7678Automatic indentation on newlines provided by the SQL formatting feature is disabled by default.
7779
7880To enable auto-indentation, toggle the corresponding flag in the settings screen below.
@@ -81,6 +83,65 @@ To enable auto-indentation, toggle the corresponding flag in the settings screen
8183
8284![ Format.gif] ( images/gif/Format.gif )
8385
86+ ### Limitations
87+ The current formatter has the following limitations:
88+
89+ - ** No customizable indentation** : The number of spaces for indentation is fixed and cannot be changed
90+ - ** No customizable line breaks** : You cannot configure which keywords trigger line breaks
91+ - ** No custom function registration** : User-defined functions cannot be registered for formatting rules
92+ - ** No formatting style options** : Cannot choose between different formatting styles or conventions
93+
94+ ### Formatting Features
95+ The SQL formatter supports the following formatting capabilities:
96+
97+ - ** SQL Keywords** : Converts keywords to uppercase (SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, etc.)
98+ - ** Statement Structure** : Properly formats different SQL statement types:
99+ - SELECT statements with proper column and clause alignment
100+ - INSERT statements with formatted column lists and VALUES clauses
101+ - UPDATE statements with aligned SET clauses
102+ - DELETE statements with formatted conditions
103+ - WITH clauses (CTE) with proper indentation
104+ - ** Joins** : Formats JOIN operations with appropriate indentation and alignment
105+ - ** Subqueries** : Properly indents nested queries and subselects
106+ - ** Functions** : Formats function calls with proper parameter alignment
107+ - ** Comments** : Preserves single-line (--) and multi-line (/* * /) comments
108+ - ** Doma Directives** : Maintains proper formatting for Doma-specific directives:
109+ - Bind variables: ` /* paramName */ ` with proper spacing
110+ - Conditional directives: ` /*%if condition */ ` ... ` /*%end*/ `
111+ - Loop directives: ` /*%for item : collection */ ` ... ` /*%end*/ `
112+ - Expand directive: ` /*%expand */ `
113+ - Populate directive: ` /*%populate */ `
114+ - Static property calls: ` /* @ClassName@property */ `
115+ - Literal values: ` /*^ literalValue */ `
116+ - Embedded variables: ` /*# variable */ `
117+
118+ ### Examples
119+
120+ ** Before formatting:**
121+ ``` sql
122+ SELECT COUNT (DISTINCT x) AS count_x, o.* , COALESCE(nbor .nearest , 999 )
123+ AS nearest FROM ( SELECT p .objid , p .psfmag_g - p .extinction_g AS rpm
124+ FROM phototag p JOIN usno u ON p .objid = u .objid
125+ WHERE p .TYPE = ' Star' /* %if status == 2 */ and u .propermotion > 2 .0 /* %end*/ ) as o
126+ ```
127+
128+ ** After formatting:**
129+ ``` sql
130+ SELECT COUNT (DISTINCT x) AS count_x
131+ , o.*
132+ , COALESCE(nbor .nearest
133+ , 999 ) AS nearest
134+ FROM ( SELECT p .objid
135+ , p .psfmag_g - p .extinction_g AS rpm
136+ FROM phototag p
137+ JOIN usno u
138+ ON p .objid = u .objid
139+ WHERE p .TYPE = ' Star'
140+ /* %if status == 2 */
141+ AND u .propermotion > 2 .0
142+ /* %end*/ ) AS o
143+ ```
144+
84145## Reference Contributor
85146Ctrl+Click on a bind variable in an SQL file to jump to its source symbol.
86147
0 commit comments