Skip to content

Commit fd93ff9

Browse files
committed
fix #125: add more alias funcs in Cond for readability
1 parent 92fd859 commit fd93ff9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cond.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func (c *Cond) E(field string, value interface{}) string {
2626
return c.Equal(field, value)
2727
}
2828

29+
// EQ is an alias of Equal.
30+
func (c *Cond) EQ(field string, value interface{}) string {
31+
return c.Equal(field, value)
32+
}
33+
2934
// NotEqual represents "field <> value".
3035
func (c *Cond) NotEqual(field string, value interface{}) string {
3136
buf := newStringBuilder()
@@ -40,6 +45,11 @@ func (c *Cond) NE(field string, value interface{}) string {
4045
return c.NotEqual(field, value)
4146
}
4247

48+
// NEQ is an alias of NotEqual.
49+
func (c *Cond) NEQ(field string, value interface{}) string {
50+
return c.NotEqual(field, value)
51+
}
52+
4353
// GreaterThan represents "field > value".
4454
func (c *Cond) GreaterThan(field string, value interface{}) string {
4555
buf := newStringBuilder()
@@ -54,6 +64,11 @@ func (c *Cond) G(field string, value interface{}) string {
5464
return c.GreaterThan(field, value)
5565
}
5666

67+
// GT is an alias of GreaterThan.
68+
func (c *Cond) GT(field string, value interface{}) string {
69+
return c.GreaterThan(field, value)
70+
}
71+
5772
// GreaterEqualThan represents "field >= value".
5873
func (c *Cond) GreaterEqualThan(field string, value interface{}) string {
5974
buf := newStringBuilder()
@@ -68,6 +83,11 @@ func (c *Cond) GE(field string, value interface{}) string {
6883
return c.GreaterEqualThan(field, value)
6984
}
7085

86+
// GTE is an alias of GreaterEqualThan.
87+
func (c *Cond) GTE(field string, value interface{}) string {
88+
return c.GreaterEqualThan(field, value)
89+
}
90+
7191
// LessThan represents "field < value".
7292
func (c *Cond) LessThan(field string, value interface{}) string {
7393
buf := newStringBuilder()
@@ -82,6 +102,11 @@ func (c *Cond) L(field string, value interface{}) string {
82102
return c.LessThan(field, value)
83103
}
84104

105+
// LT is an alias of LessThan.
106+
func (c *Cond) LT(field string, value interface{}) string {
107+
return c.LessThan(field, value)
108+
}
109+
85110
// LessEqualThan represents "field <= value".
86111
func (c *Cond) LessEqualThan(field string, value interface{}) string {
87112
buf := newStringBuilder()
@@ -96,6 +121,11 @@ func (c *Cond) LE(field string, value interface{}) string {
96121
return c.LessEqualThan(field, value)
97122
}
98123

124+
// LTE is an alias of LessEqualThan.
125+
func (c *Cond) LTE(field string, value interface{}) string {
126+
return c.LessEqualThan(field, value)
127+
}
128+
99129
// In represents "field IN (value...)".
100130
func (c *Cond) In(field string, value ...interface{}) string {
101131
vs := make([]string, 0, len(value))

cond_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ func TestCond(t *testing.T) {
1414
cases := map[string]func() string{
1515
"$$a = $0": func() string { return newTestCond().Equal("$a", 123) },
1616
"$$b = $0": func() string { return newTestCond().E("$b", 123) },
17+
"$$c = $0": func() string { return newTestCond().EQ("$c", 123) },
1718
"$$a <> $0": func() string { return newTestCond().NotEqual("$a", 123) },
1819
"$$b <> $0": func() string { return newTestCond().NE("$b", 123) },
20+
"$$c <> $0": func() string { return newTestCond().NEQ("$c", 123) },
1921
"$$a > $0": func() string { return newTestCond().GreaterThan("$a", 123) },
2022
"$$b > $0": func() string { return newTestCond().G("$b", 123) },
23+
"$$c > $0": func() string { return newTestCond().GT("$c", 123) },
2124
"$$a >= $0": func() string { return newTestCond().GreaterEqualThan("$a", 123) },
2225
"$$b >= $0": func() string { return newTestCond().GE("$b", 123) },
26+
"$$c >= $0": func() string { return newTestCond().GTE("$c", 123) },
2327
"$$a < $0": func() string { return newTestCond().LessThan("$a", 123) },
2428
"$$b < $0": func() string { return newTestCond().L("$b", 123) },
29+
"$$c < $0": func() string { return newTestCond().LT("$c", 123) },
2530
"$$a <= $0": func() string { return newTestCond().LessEqualThan("$a", 123) },
2631
"$$b <= $0": func() string { return newTestCond().LE("$b", 123) },
32+
"$$c <= $0": func() string { return newTestCond().LTE("$c", 123) },
2733
"$$a IN ($0, $1, $2)": func() string { return newTestCond().In("$a", 1, 2, 3) },
2834
"$$a NOT IN ($0, $1, $2)": func() string { return newTestCond().NotIn("$a", 1, 2, 3) },
2935
"$$a LIKE $0": func() string { return newTestCond().Like("$a", "%Huan%") },

0 commit comments

Comments
 (0)