AddJoin returns a Rule that appends a JOIN clause to the SELECT statement. The join type is validated against the set of supported types; an error is returned for any unrecognised value. Parameters: - joinType: One of INNER, LEFT, RIGHT, FULL, CROSS, or NATURAL (case-insensitive) - table: Name of t
(joinType string, table string, condition ast.Expression)
| 43 | // Returns an error for unrecognised join types or ErrUnsupportedStatement for |
| 44 | // non-SELECT statements. |
| 45 | func AddJoin(joinType string, table string, condition ast.Expression) Rule { |
| 46 | return RuleFunc(func(stmt ast.Statement) error { |
| 47 | upper := strings.ToUpper(joinType) |
| 48 | if !validJoinTypes[upper] { |
| 49 | return fmt.Errorf("AddJoin: unknown join type %q (valid: INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)", joinType) |
| 50 | } |
| 51 | sel, err := getSelect(stmt, "AddJoin") |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | sel.Joins = append(sel.Joins, ast.JoinClause{ |
| 56 | Type: upper, |
| 57 | Right: ast.TableReference{Name: table}, |
| 58 | Condition: condition, |
| 59 | }) |
| 60 | return nil |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | // RemoveJoin returns a Rule that removes all JOIN clauses whose right-hand table name |
| 65 | // or alias matches tableName (case-insensitive). If no matching JOIN exists the |