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

Function TestQuery_JSONBComplexQuery

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

Source from the content-addressed store, hash-verified

351}
352
353func TestQuery_JSONBComplexQuery(t *testing.T) {
354 // Realistic example from the codebase
355 q := Q().Space("SELECT * FROM revision").
356 Where("TRUE").
357 And("instance = ?", "prod").
358 And("db_name = ?", "main").
359 And("payload->>'type' = ?", "MIGRATE").
360 And("payload ?? 'schema_version'").
361 And("deleted_at IS NULL").
362 Space("ORDER BY version DESC").
363 Space("LIMIT ?", 10)
364 sql, args, err := q.ToSQL()
365 require.NoError(t, err)
366 require.Equal(t, "SELECT * FROM revision WHERE TRUE AND instance = $1 AND db_name = $2 AND payload->>'type' = $3 AND payload ? 'schema_version' AND deleted_at IS NULL ORDER BY version DESC LIMIT $4", sql)
367 require.Equal(t, []any{"prod", "main", "MIGRATE", 10}, args)
368}
369
370func TestQuery_EscapedQuestionMarks(t *testing.T) {
371 // Test multiple ?? in a row - need to escape each ?

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected