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

Function onConflictSQL

pkg/sql/ast/sql.go:1429–1457  ·  view source on GitHub ↗
(oc *OnConflict)

Source from the content-addressed store, hash-verified

1427}
1428
1429func onConflictSQL(oc *OnConflict) string {
1430 sb := getBuilder()
1431 defer putBuilder(sb)
1432 sb.WriteString(" ON CONFLICT")
1433 if len(oc.Target) > 0 {
1434 sb.WriteString(" (")
1435 sb.WriteString(exprListSQL(oc.Target))
1436 sb.WriteString(")")
1437 }
1438 if oc.Constraint != "" {
1439 sb.WriteString(" ON CONSTRAINT ")
1440 sb.WriteString(oc.Constraint)
1441 }
1442 if oc.Action.DoNothing {
1443 sb.WriteString(" DO NOTHING")
1444 } else if len(oc.Action.DoUpdate) > 0 {
1445 sb.WriteString(" DO UPDATE SET ")
1446 upds := make([]string, len(oc.Action.DoUpdate))
1447 for i, u := range oc.Action.DoUpdate {
1448 upds[i] = exprSQL(u.Column) + " = " + exprSQL(u.Value)
1449 }
1450 sb.WriteString(strings.Join(upds, ", "))
1451 if oc.Action.Where != nil {
1452 sb.WriteString(" WHERE ")
1453 sb.WriteString(exprSQL(oc.Action.Where))
1454 }
1455 }
1456 return sb.String()
1457}
1458
1459func columnDefSQL(c *ColumnDef) string {
1460 sb := getBuilder()

Callers 1

SQLMethod · 0.70

Calls 5

getBuilderFunction · 0.85
putBuilderFunction · 0.85
exprListSQLFunction · 0.70
exprSQLFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected