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

Function TestQuery_ConditionalBuilding

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

Source from the content-addressed store, hash-verified

155}
156
157func TestQuery_ConditionalBuilding(t *testing.T) {
158 // Simulate building a query with optional filters
159 id := 123
160 name := "Alice"
161 var status *string // nil
162
163 q := Q().Space("SELECT * FROM users").Where("TRUE")
164
165 if id != 0 {
166 q.And("id = ?", id)
167 }
168 if name != "" {
169 q.And("name = ?", name)
170 }
171 if status != nil { //nolint:govet
172 q.And("status = ?", *status)
173 }
174
175 sql, args, err := q.ToSQL()
176 require.NoError(t, err)
177 require.Equal(t, "SELECT * FROM users WHERE TRUE AND id = $1 AND name = $2", sql)
178 require.Equal(t, []any{123, "Alice"}, args)
179}
180
181func TestQuery_Composition(t *testing.T) {
182 // Build query parts separately

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected