fix(cmd): handle errors and improve output formatting
* update error handling in various commands to use blank identifier * enhance output formatting for better readability * add golangci-lint to Makefile for linting checks
This commit is contained in:
+9
-16
@@ -10,16 +10,13 @@ import (
|
||||
|
||||
// isDMLStart reports whether toks begins with a DML statement keyword.
|
||||
func isDMLStart(toks []cst.Tok) bool {
|
||||
for _, t := range toks {
|
||||
if t.Tok.Kind == lexer.Ident {
|
||||
switch lowerASCII(t.Tok.Text) {
|
||||
case "select", "insert", "update", "delete", "with":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if len(toks) == 0 || toks[0].Tok.Kind != lexer.Ident {
|
||||
return false
|
||||
}
|
||||
switch lowerASCII(toks[0].Tok.Text) {
|
||||
case "select", "insert", "update", "delete", "with":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -510,13 +507,6 @@ func dmlSplitCommas(toks []cst.Tok) [][]cst.Tok {
|
||||
return items
|
||||
}
|
||||
|
||||
// dmlColList formats kwText followed by a comma-separated body.
|
||||
// One item: kept on the same line as the keyword.
|
||||
// Multiple items: each on its own line with the configured comma style.
|
||||
func dmlColList(kwText string, items [][]cst.Tok, st config.Style) string {
|
||||
return dmlColListSelect(kwText, items, st)
|
||||
}
|
||||
|
||||
// dmlColListSelect formats a SELECT / RETURNING column list with optional
|
||||
// align_columns and select_align_as settings.
|
||||
func dmlColListSelect(kwText string, items [][]cst.Tok, st config.Style) string {
|
||||
@@ -627,7 +617,10 @@ func dmlColListSet(kwText string, items [][]cst.Tok, st config.Style) string {
|
||||
// alias names align vertically.
|
||||
func alignSelectItems(texts []string, st config.Style) []string {
|
||||
// Split each text into (expr, " AS ", alias) or keep as-is.
|
||||
type part struct{ expr, alias string; hasAs bool }
|
||||
type part struct {
|
||||
expr, alias string
|
||||
hasAs bool
|
||||
}
|
||||
parts := make([]part, len(texts))
|
||||
maxExpr := 0
|
||||
for i, t := range texts {
|
||||
|
||||
@@ -68,6 +68,6 @@ to_char to_date to_json to_jsonb to_number to_timestamp to_tsvector
|
||||
translate trim trunc unnest upper width_bucket
|
||||
`)
|
||||
|
||||
func isKeyword(lower string) bool { return keywords[lower] }
|
||||
func isTypeName(lower string) bool { return typeNames[lower] }
|
||||
func isBuiltinFunc(lower string) bool { return builtinFunctions[lower] }
|
||||
func isKeyword(lower string) bool { return keywords[lower] }
|
||||
func isTypeName(lower string) bool { return typeNames[lower] }
|
||||
func isBuiltinFunc(lower string) bool { return builtinFunctions[lower] }
|
||||
|
||||
Reference in New Issue
Block a user