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

Function AddReturning

pkg/transform/returning.go:51–62  ·  view source on GitHub ↗

AddReturning returns a Rule that appends one or more column names to the RETURNING clause of an INSERT, UPDATE, or DELETE statement. This is the standard PostgreSQL extension for returning row data from DML operations. SQL Server users can achieve a similar result with the OUTPUT clause (not yet cov

(columns ...string)

Source from the content-addressed store, hash-verified

49//
50// transform.Apply(stmt, transform.AddReturning("id", "created_at"))
51func AddReturning(columns ...string) Rule {
52 return RuleFunc(func(stmt ast.Statement) error {
53 ret, err := getReturning(stmt)
54 if err != nil {
55 return err
56 }
57 for _, col := range columns {
58 *ret = append(*ret, &ast.Identifier{Name: col})
59 }
60 return nil
61 })
62}
63
64// RemoveReturning returns a Rule that clears the entire RETURNING clause from
65// an INSERT, UPDATE, or DELETE statement. If the clause is already empty the

Calls 2

RuleFuncFuncType · 0.85
getReturningFunction · 0.85