1111# copies or substantial portions of the Software.
1212# File: python/sqlformat.py
1313
14+ from typing import Optional , Union
15+
1416import sqlparse
1517import vim
1618
1719
18- def format_sql (sql , indent , keyword_case , line_width = 80 ):
19- """
20- Format SQL code using sqlparse.
21-
20+ def format_sql (
21+ sql : str ,
22+ indent : int ,
23+ keyword_case : Optional [str ],
24+ line_width : int = 80 ,
25+ ) -> str :
26+ """Format SQL code using sqlparse.
27+
2228 Args:
23- sql (str): SQL code to format
24- indent (int): Number of spaces for indentation
25- keyword_case (str): 'upper', 'lower', or None for keyword case
26- line_width (int): Maximum line width for wrapping
29+ sql: SQL code to format
30+ indent: Number of spaces for indentation
31+ keyword_case: 'upper', 'lower', or None for keyword case
32+ line_width: Maximum line width for wrapping
33+
2734 Returns:
28- str: Formatted SQL
35+ Formatted SQL string
36+
37+ Raises:
38+ ValueError: If input parameters are invalid
2939 """
3040 try :
3141 vim .command ('echo "Formatting SQL..."' )
32-
42+
3343 # Validate inputs
3444 if not isinstance (indent , int ) or indent < 0 :
3545 raise ValueError ("Indent must be a positive integer" )
@@ -46,10 +56,10 @@ def format_sql(sql, indent, keyword_case, line_width=80):
4656 keyword_case = keyword_case ,
4757 wrap_after = line_width ,
4858 )
49-
59+
5060 vim .command ('echo "SQL formatting complete"' )
5161 return formatted
52-
62+
5363 except Exception as e :
5464 error_msg = f"SQL formatting failed: { str (e )} "
5565 vim .command (f'echoerr "{ error_msg } "' )
0 commit comments