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

Function AddJoin

pkg/transform/joins.go:45–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43// Returns an error for unrecognised join types or ErrUnsupportedStatement for
44// non-SELECT statements.
45func 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

Callers 3

TestAddJoinFunction · 0.85
TestAddJoin_InvalidTypeFunction · 0.85

Calls 3

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
ErrorfMethod · 0.65

Tested by 3

TestAddJoinFunction · 0.68
TestAddJoin_InvalidTypeFunction · 0.68