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

Function AddJoinFromSQL

pkg/transform/joins.go:98–111  ·  view source on GitHub ↗

AddJoinFromSQL returns a Rule that parses a JOIN clause from SQL and adds it to a SELECT statement. The sql parameter should be a complete JOIN clause, e.g. "LEFT JOIN orders ON orders.user_id = users.id". WARNING: sql parameter must not contain untrusted user input. This function parses raw SQL -

(sql string)

Source from the content-addressed store, hash-verified

96// produce unintended query modifications. Use parameterized queries
97// or construct AST nodes directly for untrusted input.
98func AddJoinFromSQL(sql string) Rule {
99 return RuleFunc(func(stmt ast.Statement) error {
100 join, err := parseJoinClause(sql)
101 if err != nil {
102 return err
103 }
104 sel, err := getSelect(stmt, "AddJoinFromSQL")
105 if err != nil {
106 return err
107 }
108 sel.Joins = append(sel.Joins, *join)
109 return nil
110 })
111}

Callers 2

mainFunction · 0.92
TestAddJoinFromSQLFunction · 0.85

Calls 3

RuleFuncFuncType · 0.85
parseJoinClauseFunction · 0.85
getSelectFunction · 0.85

Tested by 1

TestAddJoinFromSQLFunction · 0.68