Apply executes one or more rules against an AST statement in the order they are provided. If any rule returns a non-nil error the function stops immediately and returns that error without applying subsequent rules. This is the primary entry point for composing transforms: err := transform.Apply(s
(stmt ast.Statement, rules ...Rule)
| 82 | // transform.AddOrderBy("created_at", true), |
| 83 | // ) |
| 84 | func Apply(stmt ast.Statement, rules ...Rule) error { |
| 85 | for _, rule := range rules { |
| 86 | if err := rule.Apply(stmt); err != nil { |
| 87 | return err |
| 88 | } |
| 89 | } |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | // ErrUnsupportedStatement is returned when a transform rule is applied to a statement |
| 94 | // type it does not support. For example, AddColumn only supports SelectStatement; applying |