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

Function TestExprRecursion

expr_test.go:424–458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

422}
423
424func TestExprRecursion(t *testing.T) {
425 {
426 b := Expr("count(?)", Expr("nullif(a,?)", "b"))
427 sql, args, err := b.ToSql()
428 assert.NoError(t, err)
429
430 expectedSql := "count(nullif(a,?))"
431 assert.Equal(t, expectedSql, sql)
432
433 expectedArgs := []interface{}{"b"}
434 assert.Equal(t, expectedArgs, args)
435 }
436 {
437 b := Expr("extract(? from ?)", Expr("epoch"), "2001-02-03")
438 sql, args, err := b.ToSql()
439 assert.NoError(t, err)
440
441 expectedSql := "extract(epoch from ?)"
442 assert.Equal(t, expectedSql, sql)
443
444 expectedArgs := []interface{}{"2001-02-03"}
445 assert.Equal(t, expectedArgs, args)
446 }
447 {
448 b := Expr("JOIN t1 ON ?", And{Eq{"id": 1}, Expr("NOT c1"), Expr("? @@ ?", "x", "y")})
449 sql, args, err := b.ToSql()
450 assert.NoError(t, err)
451
452 expectedSql := "JOIN t1 ON (id = ? AND NOT c1 AND ? @@ ?)"
453 assert.Equal(t, expectedSql, sql)
454
455 expectedArgs := []interface{}{1, "x", "y"}
456 assert.Equal(t, expectedArgs, args)
457 }
458}
459
460func ExampleEq() {
461 Select("id", "created", "first_name").From("users").Where(Eq{

Callers

nothing calls this directly

Calls 2

ExprFunction · 0.85
ToSqlMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…