Skip to content

Commit

Permalink
Expose internal RawBool type
Browse files Browse the repository at this point in the history
  • Loading branch information
go-jet committed Apr 17, 2023
1 parent a428981 commit 0a7e0b5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/jet/literal_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ func RawWithParent(raw string, parent ...Expression) Expression {
return rawExp
}

// RawBool helper that for raw string boolean expressions
func RawBool(raw string, namedArgs ...map[string]interface{}) BoolExpression {
return BoolExp(Raw(raw, namedArgs...))
}

// RawInt helper that for integer expressions
func RawInt(raw string, namedArgs ...map[string]interface{}) IntegerExpression {
return IntExp(Raw(raw, namedArgs...))
Expand Down
1 change: 1 addition & 0 deletions mysql/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type RawArgs = map[string]interface{}
var (
Raw = jet.Raw

RawBool = jet.RawBool
RawInt = jet.RawInt
RawFloat = jet.RawFloat
RawString = jet.RawString
Expand Down
3 changes: 3 additions & 0 deletions mysql/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func TestRawInvalidArguments(t *testing.T) {
}

func TestRawType(t *testing.T) {
assertSerialize(t, RawBool("table.colInt < :float", RawArgs{":float": 11.22}).IS_FALSE(),
"(table.colInt < ?) IS FALSE", 11.22)

assertSerialize(t, RawFloat("table.colInt + &float", RawArgs{"&float": 11.22}).EQ(Float(3.14)),
"((table.colInt + ?) = ?)", 11.22, 3.14)
assertSerialize(t, RawString("table.colStr || str", RawArgs{"str": "doe"}).EQ(String("john doe")),
Expand Down
1 change: 1 addition & 0 deletions postgres/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type RawArgs = map[string]interface{}
var (
Raw = jet.Raw

RawBool = jet.RawBool
RawInt = jet.RawInt
RawFloat = jet.RawFloat
RawString = jet.RawString
Expand Down
3 changes: 3 additions & 0 deletions postgres/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func TestRawInvalidArguments(t *testing.T) {
}

func TestRawHelperMethods(t *testing.T) {
assertSerialize(t, RawBool("table.colInt < :float", RawArgs{":float": 11.22}).IS_FALSE(),
"(table.colInt < $1) IS FALSE", 11.22)

assertSerialize(t, RawFloat("table.colInt + :float", RawArgs{":float": 11.22}).EQ(Float(3.14)),
"((table.colInt + $1) = $2)", 11.22, 3.14)
assertSerialize(t, RawString("table.colStr || str", RawArgs{"str": "doe"}).EQ(String("john doe")),
Expand Down
1 change: 1 addition & 0 deletions sqlite/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type RawArgs = map[string]interface{}
var (
Raw = jet.Raw

RawBool = jet.RawBool
RawInt = jet.RawInt
RawFloat = jet.RawFloat
RawString = jet.RawString
Expand Down
3 changes: 3 additions & 0 deletions sqlite/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestRawInvalidArguments(t *testing.T) {
}

func TestRawType(t *testing.T) {
assertSerialize(t, RawBool("table.colInt < :float", RawArgs{":float": 11.22}).IS_FALSE(),
"(table.colInt < ?) IS FALSE", 11.22)

assertSerialize(t, RawFloat("table.colInt + &float", RawArgs{"&float": 11.22}).EQ(Float(3.14)),
"((table.colInt + ?) = ?)", 11.22, 3.14)
assertSerialize(t, RawString("table.colStr || str", RawArgs{"str": "doe"}).EQ(String("john doe")),
Expand Down

0 comments on commit 0a7e0b5

Please sign in to comment.