formatSQLInternal formats a SQL string using the provided options.
(sql string, indentSize int, uppercaseKeywords, addSemicolon bool)
| 75 | |
| 76 | // formatSQLInternal formats a SQL string using the provided options. |
| 77 | func formatSQLInternal(sql string, indentSize int, uppercaseKeywords, addSemicolon bool) (map[string]any, error) { |
| 78 | if sql == "" { |
| 79 | return nil, fmt.Errorf("parameter 'sql' is required and must not be empty") |
| 80 | } |
| 81 | |
| 82 | opts := gosqlx.FormatOptions{ |
| 83 | IndentSize: indentSize, |
| 84 | UppercaseKeywords: uppercaseKeywords, |
| 85 | AddSemicolon: addSemicolon, |
| 86 | } |
| 87 | |
| 88 | formatted, err := gosqlx.Format(sql, opts) |
| 89 | if err != nil { |
| 90 | return nil, fmt.Errorf("format failed: %w", err) |
| 91 | } |
| 92 | |
| 93 | return map[string]any{ |
| 94 | "formatted_sql": formatted, |
| 95 | "options": map[string]any{ |
| 96 | "indent_size": indentSize, |
| 97 | "uppercase_keywords": uppercaseKeywords, |
| 98 | "add_semicolon": addSemicolon, |
| 99 | }, |
| 100 | }, nil |
| 101 | } |
| 102 | |
| 103 | // parseSQLInternal parses a SQL string and returns statement count and types. |
| 104 | func parseSQLInternal(sql string) (map[string]any, error) { |