Skip to content

Commit

Permalink
fix #125: add more alias funcs in Cond for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
huandu committed Nov 4, 2023
1 parent 92fd859 commit fd93ff9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (c *Cond) E(field string, value interface{}) string {
return c.Equal(field, value)
}

// EQ is an alias of Equal.
func (c *Cond) EQ(field string, value interface{}) string {
return c.Equal(field, value)
}

// NotEqual represents "field <> value".
func (c *Cond) NotEqual(field string, value interface{}) string {
buf := newStringBuilder()
Expand All @@ -40,6 +45,11 @@ func (c *Cond) NE(field string, value interface{}) string {
return c.NotEqual(field, value)
}

// NEQ is an alias of NotEqual.
func (c *Cond) NEQ(field string, value interface{}) string {
return c.NotEqual(field, value)
}

// GreaterThan represents "field > value".
func (c *Cond) GreaterThan(field string, value interface{}) string {
buf := newStringBuilder()
Expand All @@ -54,6 +64,11 @@ func (c *Cond) G(field string, value interface{}) string {
return c.GreaterThan(field, value)
}

// GT is an alias of GreaterThan.
func (c *Cond) GT(field string, value interface{}) string {
return c.GreaterThan(field, value)
}

// GreaterEqualThan represents "field >= value".
func (c *Cond) GreaterEqualThan(field string, value interface{}) string {
buf := newStringBuilder()
Expand All @@ -68,6 +83,11 @@ func (c *Cond) GE(field string, value interface{}) string {
return c.GreaterEqualThan(field, value)
}

// GTE is an alias of GreaterEqualThan.
func (c *Cond) GTE(field string, value interface{}) string {
return c.GreaterEqualThan(field, value)
}

// LessThan represents "field < value".
func (c *Cond) LessThan(field string, value interface{}) string {
buf := newStringBuilder()
Expand All @@ -82,6 +102,11 @@ func (c *Cond) L(field string, value interface{}) string {
return c.LessThan(field, value)
}

// LT is an alias of LessThan.
func (c *Cond) LT(field string, value interface{}) string {
return c.LessThan(field, value)
}

// LessEqualThan represents "field <= value".
func (c *Cond) LessEqualThan(field string, value interface{}) string {
buf := newStringBuilder()
Expand All @@ -96,6 +121,11 @@ func (c *Cond) LE(field string, value interface{}) string {
return c.LessEqualThan(field, value)
}

// LTE is an alias of LessEqualThan.
func (c *Cond) LTE(field string, value interface{}) string {
return c.LessEqualThan(field, value)
}

// In represents "field IN (value...)".
func (c *Cond) In(field string, value ...interface{}) string {
vs := make([]string, 0, len(value))
Expand Down
6 changes: 6 additions & 0 deletions cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ func TestCond(t *testing.T) {
cases := map[string]func() string{
"$$a = $0": func() string { return newTestCond().Equal("$a", 123) },
"$$b = $0": func() string { return newTestCond().E("$b", 123) },
"$$c = $0": func() string { return newTestCond().EQ("$c", 123) },
"$$a <> $0": func() string { return newTestCond().NotEqual("$a", 123) },
"$$b <> $0": func() string { return newTestCond().NE("$b", 123) },
"$$c <> $0": func() string { return newTestCond().NEQ("$c", 123) },
"$$a > $0": func() string { return newTestCond().GreaterThan("$a", 123) },
"$$b > $0": func() string { return newTestCond().G("$b", 123) },
"$$c > $0": func() string { return newTestCond().GT("$c", 123) },
"$$a >= $0": func() string { return newTestCond().GreaterEqualThan("$a", 123) },
"$$b >= $0": func() string { return newTestCond().GE("$b", 123) },
"$$c >= $0": func() string { return newTestCond().GTE("$c", 123) },
"$$a < $0": func() string { return newTestCond().LessThan("$a", 123) },
"$$b < $0": func() string { return newTestCond().L("$b", 123) },
"$$c < $0": func() string { return newTestCond().LT("$c", 123) },
"$$a <= $0": func() string { return newTestCond().LessEqualThan("$a", 123) },
"$$b <= $0": func() string { return newTestCond().LE("$b", 123) },
"$$c <= $0": func() string { return newTestCond().LTE("$c", 123) },
"$$a IN ($0, $1, $2)": func() string { return newTestCond().In("$a", 1, 2, 3) },
"$$a NOT IN ($0, $1, $2)": func() string { return newTestCond().NotIn("$a", 1, 2, 3) },
"$$a LIKE $0": func() string { return newTestCond().Like("$a", "%Huan%") },
Expand Down

0 comments on commit fd93ff9

Please sign in to comment.