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

Function TestQuery_ConditionalOrWhereClause

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

Source from the content-addressed store, hash-verified

735}
736
737func TestQuery_ConditionalOrWhereClause(t *testing.T) {
738 // Test building WHERE clause with only Or() calls - pattern from actual codebase
739 // This tests that the first Or() doesn't add " OR " prefix
740 where := Q()
741
742 // First condition
743 environmentID := "prod"
744 where.Or("environment = ?", environmentID)
745
746 // Multiple database conditions
747 databases := []struct {
748 InstanceID string
749 DatabaseName string
750 }{
751 {"inst-1", "db-1"},
752 {"inst-2", "db-2"},
753 }
754
755 for _, db := range databases {
756 where.Or("(db.instance = ? AND db.name = ?)", db.InstanceID, db.DatabaseName)
757 }
758
759 // Build final UPDATE query
760 set := Q().Comma("project = ?", "proj-123")
761 q := Q().Space("UPDATE db SET ?", set).Space("WHERE ?", where)
762
763 sql, args, err := q.ToSQL()
764 require.NoError(t, err)
765 require.Equal(t, "UPDATE db SET project = $1 WHERE environment = $2 OR (db.instance = $3 AND db.name = $4) OR (db.instance = $5 AND db.name = $6)", sql)
766 require.Equal(t, []any{"proj-123", "prod", "inst-1", "db-1", "inst-2", "db-2"}, args)
767}
768
769func TestQuery_ConditionalOrOnlyDatabases(t *testing.T) {
770 // Test when only database conditions exist (no environment filter)

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected