MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestQuery_UpdateWithComplexSet

Function TestQuery_UpdateWithComplexSet

backend/common/qb/qb_test.go:651–677  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

649}
650
651func TestQuery_UpdateWithComplexSet(t *testing.T) {
652 // Complex UPDATE with conditional SET fields and JSONB
653 id := 123
654 name := "Updated Name"
655 updateMetadata := true
656 metadataKey := "version"
657 metadataValue := "2.0"
658
659 set := Q()
660 set.Comma("name = ?", name)
661 set.Comma("updated_at = NOW()")
662
663 if updateMetadata {
664 set.Comma("metadata = jsonb_set(metadata, ?, ?)", "{"+metadataKey+"}", metadataValue)
665 }
666
667 where := Q().Space("id = ?", id).And("deleted_at IS NULL")
668
669 q := Q().Space("UPDATE tasks SET ?", set).
670 Space("WHERE ?", where).
671 Space("RETURNING *")
672
673 sql, args, err := q.ToSQL()
674 require.NoError(t, err)
675 require.Equal(t, "UPDATE tasks SET name = $1, updated_at = NOW(), metadata = jsonb_set(metadata, $2, $3) WHERE id = $4 AND deleted_at IS NULL RETURNING *", sql)
676 require.Equal(t, []any{name, "{" + metadataKey + "}", metadataValue, id}, args)
677}
678
679func TestQuery_InsertWithReturning(t *testing.T) {
680 // INSERT with RETURNING clause

Callers

nothing calls this directly

Calls 6

QFunction · 0.85
CommaMethod · 0.80
AndMethod · 0.80
SpaceMethod · 0.80
ToSQLMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected