MCPcopy
hub / github.com/Masterminds/squirrel / TestSelectJoinClausePlaceholderNumbering

Function TestSelectJoinClausePlaceholderNumbering

select_test.go:282–296  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestSelectJoinClausePlaceholderNumbering(t *testing.T) {
283 subquery := Select("a").Where(Eq{"b": 2}).PlaceholderFormat(Dollar)
284
285 sql, args, err := Select("t1.a").
286 From("t1").
287 Where(Eq{"a": 1}).
288 JoinClause(subquery.Prefix("JOIN (").Suffix(") t2 ON (t1.a = t2.a)")).
289 PlaceholderFormat(Dollar).
290 ToSql()
291 assert.NoError(t, err)
292
293 expectedSql := "SELECT t1.a FROM t1 JOIN ( SELECT a WHERE b = $1 ) t2 ON (t1.a = t2.a) WHERE a = $2"
294 assert.Equal(t, expectedSql, sql)
295 assert.Equal(t, []interface{}{2, 1}, args)
296}
297
298func ExampleSelect() {
299 Select("id", "created", "first_name").From("users") // ... continue building up your query

Callers

nothing calls this directly

Calls 8

SelectFunction · 0.85
JoinClauseMethod · 0.80
ToSqlMethod · 0.65
PlaceholderFormatMethod · 0.45
WhereMethod · 0.45
FromMethod · 0.45
SuffixMethod · 0.45
PrefixMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…