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)
| 49 | // |
| 50 | // transform.Apply(stmt, transform.AddReturning("id", "created_at")) |
| 51 | func 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 |