MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / expandUpdateStmt

Method expandUpdateStmt

internal/x/expander/expander.go:240–262  ·  view source on GitHub ↗

expandUpdateStmt expands * in an UPDATE statement's RETURNING clause

(ctx context.Context, stmt *ast.UpdateStmt)

Source from the content-addressed store, hash-verified

238
239// expandUpdateStmt expands * in an UPDATE statement's RETURNING clause
240func (e *Expander) expandUpdateStmt(ctx context.Context, stmt *ast.UpdateStmt) error {
241 // Expand CTEs first
242 if stmt.WithClause != nil && stmt.WithClause.Ctes != nil {
243 for _, cte := range stmt.WithClause.Ctes.Items {
244 if err := e.expandNode(ctx, cte); err != nil {
245 return err
246 }
247 }
248 }
249
250 // Expand RETURNING clause
251 if hasStarInList(stmt.ReturningList) {
252 tempRaw := &ast.RawStmt{Stmt: stmt}
253 tempQuery := ast.Format(tempRaw, e.dialect)
254 columns, err := e.getColumnNames(ctx, tempQuery)
255 if err != nil {
256 return fmt.Errorf("failed to get column names: %w", err)
257 }
258 stmt.ReturningList = rewriteTargetList(stmt.ReturningList, columns)
259 }
260
261 return nil
262}
263
264// expandDeleteStmt expands * in a DELETE statement's RETURNING clause
265func (e *Expander) expandDeleteStmt(ctx context.Context, stmt *ast.DeleteStmt) error {

Callers 1

expandNodeMethod · 0.95

Calls 5

expandNodeMethod · 0.95
getColumnNamesMethod · 0.95
FormatFunction · 0.92
hasStarInListFunction · 0.85
rewriteTargetListFunction · 0.85

Tested by

no test coverage detected