Skip to content

Commit

Permalink
Return ExpBase from Cast to support further ops
Browse files Browse the repository at this point in the history
  • Loading branch information
hlubek committed May 5, 2023
1 parent cb6b42e commit ea2a941
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions builder/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ func (c junctionExp) WriteSQL(sb *SQLBuilder) {
}
}

func (b ExpBase) Cast(typ string) Exp {
return castExp{
func (b ExpBase) Cast(typ string) ExpBase {
exp := castExp{
exp: b.Exp,
typ: typ,
}
return ExpBase{Exp: exp}
}

type castExp struct {
Expand Down
11 changes: 11 additions & 0 deletions builder/op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ func TestOp(t *testing.T) {
b,
)
})

t.Run("cast and like", func(t *testing.T) {
b := qrb.N("articles.content").Cast("text").ILike(qrb.Arg("%foo%"))

testhelper.AssertSQLWriterEquals(
t,
"articles.content::text ILIKE $1",
[]any{"%foo%"},
b,
)
})
})
}

0 comments on commit ea2a941

Please sign in to comment.