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

Function renderUpdate

pkg/formatter/render.go:439–498  ·  view source on GitHub ↗
(u *ast.UpdateStatement, opts ast.FormatOptions)

Source from the content-addressed store, hash-verified

437}
438
439func renderUpdate(u *ast.UpdateStatement, opts ast.FormatOptions) string {
440 if u == nil {
441 return ""
442 }
443 f := newNodeFormatter(opts)
444 sb := f.sb
445
446 if u.With != nil {
447 sb.WriteString(renderWith(u.With, f))
448 sb.WriteString(f.clauseSep())
449 }
450
451 sb.WriteString(f.kw("UPDATE"))
452 sb.WriteString(" ")
453 sb.WriteString(u.TableName)
454 if u.Alias != "" {
455 sb.WriteString(" ")
456 sb.WriteString(u.Alias)
457 }
458
459 sb.WriteString(f.clauseSep())
460 sb.WriteString(f.kw("SET"))
461 sb.WriteString(" ")
462 upds := make([]string, len(u.Assignments))
463 for i, upd := range u.Assignments {
464 upds[i] = exprSQL(upd.Column) + " = " + exprSQL(upd.Value)
465 }
466 sb.WriteString(strings.Join(upds, ", "))
467
468 if len(u.From) > 0 {
469 sb.WriteString(f.clauseSep())
470 sb.WriteString(f.kw("FROM"))
471 sb.WriteString(" ")
472 froms := make([]string, len(u.From))
473 for i := range u.From {
474 froms[i] = tableRefSQL(&u.From[i], f)
475 }
476 sb.WriteString(strings.Join(froms, ", "))
477 }
478
479 if u.Where != nil {
480 sb.WriteString(f.clauseSep())
481 sb.WriteString(f.kw("WHERE"))
482 sb.WriteString(" ")
483 sb.WriteString(FormatExpression(u.Where, opts))
484 }
485
486 if len(u.Returning) > 0 {
487 sb.WriteString(f.clauseSep())
488 sb.WriteString(f.kw("RETURNING"))
489 sb.WriteString(" ")
490 sb.WriteString(exprListSQL(u.Returning))
491 }
492
493 if opts.AddSemicolon {
494 sb.WriteString(";")
495 }
496

Callers 1

FormatStatementFunction · 0.85

Calls 9

newNodeFormatterFunction · 0.85
renderWithFunction · 0.85
FormatExpressionFunction · 0.85
clauseSepMethod · 0.80
kwMethod · 0.80
resultMethod · 0.80
exprSQLFunction · 0.70
tableRefSQLFunction · 0.70
exprListSQLFunction · 0.70

Tested by

no test coverage detected