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

Function onConflictSQL

pkg/formatter/render.go:1422–1449  ·  view source on GitHub ↗

onConflictSQL renders an ON CONFLICT clause.

(oc *ast.OnConflict)

Source from the content-addressed store, hash-verified

1420
1421// onConflictSQL renders an ON CONFLICT clause.
1422func onConflictSQL(oc *ast.OnConflict) string {
1423 var sb strings.Builder
1424 sb.WriteString(" ON CONFLICT")
1425 if len(oc.Target) > 0 {
1426 sb.WriteString(" (")
1427 sb.WriteString(exprListSQL(oc.Target))
1428 sb.WriteString(")")
1429 }
1430 if oc.Constraint != "" {
1431 sb.WriteString(" ON CONSTRAINT ")
1432 sb.WriteString(oc.Constraint)
1433 }
1434 if oc.Action.DoNothing {
1435 sb.WriteString(" DO NOTHING")
1436 } else if len(oc.Action.DoUpdate) > 0 {
1437 sb.WriteString(" DO UPDATE SET ")
1438 upds := make([]string, len(oc.Action.DoUpdate))
1439 for i, u := range oc.Action.DoUpdate {
1440 upds[i] = exprSQL(u.Column) + " = " + exprSQL(u.Value)
1441 }
1442 sb.WriteString(strings.Join(upds, ", "))
1443 if oc.Action.Where != nil {
1444 sb.WriteString(" WHERE ")
1445 sb.WriteString(exprSQL(oc.Action.Where))
1446 }
1447 }
1448 return sb.String()
1449}
1450
1451// columnDefSQL renders a column definition.
1452func columnDefSQL(c *ast.ColumnDef) string {

Callers 1

renderInsertFunction · 0.70

Calls 3

exprListSQLFunction · 0.70
exprSQLFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected