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

Function TestOnConflictSQL

pkg/sql/ast/sql_coverage_test.go:500–532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

498}
499
500func TestOnConflictSQL(t *testing.T) {
501 // DO NOTHING
502 stmt := &InsertStatement{
503 TableName: "t",
504 Values: [][]Expression{{&LiteralValue{Value: "1"}}},
505 OnConflict: &OnConflict{
506 Target: []Expression{&Identifier{Name: "id"}},
507 Constraint: "pk",
508 Action: OnConflictAction{DoNothing: true},
509 },
510 }
511 sql := stmt.SQL()
512 if !strings.Contains(sql, "ON CONFLICT (id) ON CONSTRAINT pk DO NOTHING") {
513 t.Errorf("got: %s", sql)
514 }
515
516 // DO UPDATE with WHERE
517 stmt2 := &InsertStatement{
518 TableName: "t",
519 Values: [][]Expression{{&LiteralValue{Value: "1"}}},
520 OnConflict: &OnConflict{
521 Target: []Expression{&Identifier{Name: "id"}},
522 Action: OnConflictAction{
523 DoUpdate: []UpdateExpression{{Column: &Identifier{Name: "x"}, Value: &LiteralValue{Value: "2"}}},
524 Where: &Identifier{Name: "true"},
525 },
526 },
527 }
528 sql2 := stmt2.SQL()
529 if !strings.Contains(sql2, "DO UPDATE SET x = 2 WHERE") {
530 t.Errorf("got: %s", sql2)
531 }
532}
533
534func TestNilSQL(t *testing.T) {
535 // All nil cases should return ""

Callers

nothing calls this directly

Calls 2

SQLMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected