MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / RemoveColumn

Function RemoveColumn

pkg/transform/columns.go:57–78  ·  view source on GitHub ↗

RemoveColumn returns a Rule that removes the first column in the SELECT list that matches name. Matching is case-insensitive and checks both identifier names and expression aliases. Returns an error if no column matching name is found, or ErrUnsupportedStatement for non-SELECT statements.

(name string)

Source from the content-addressed store, hash-verified

55// Returns an error if no column matching name is found, or ErrUnsupportedStatement
56// for non-SELECT statements.
57func RemoveColumn(name string) Rule {
58 return RuleFunc(func(stmt ast.Statement) error {
59 sel, err := getSelect(stmt, "RemoveColumn")
60 if err != nil {
61 return err
62 }
63 filtered := make([]ast.Expression, 0, len(sel.Columns))
64 found := false
65 for _, col := range sel.Columns {
66 if columnMatches(col, name) {
67 found = true
68 } else {
69 filtered = append(filtered, col)
70 }
71 }
72 if !found {
73 return fmt.Errorf("column %q not found", name)
74 }
75 sel.Columns = filtered
76 return nil
77 })
78}
79
80// ReplaceColumn returns a Rule that replaces every column in the SELECT list that
81// matches oldName with a bare *ast.Identifier for newName. Matching is

Callers 4

mainFunction · 0.92
TestRemoveColumnFunction · 0.85

Calls 4

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
columnMatchesFunction · 0.85
ErrorfMethod · 0.65

Tested by 3

TestRemoveColumnFunction · 0.68