mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
Added Cond.And
This commit is contained in:
@@ -130,6 +130,11 @@ func (c *Cond) Or(orExpr ...string) string {
|
||||
return fmt.Sprintf("(%v)", strings.Join(orExpr, " OR "))
|
||||
}
|
||||
|
||||
// And represents AND logic like "expr1 AND expr2 AND expr3".
|
||||
func (c *Cond) And(andExpr ...string) string {
|
||||
return fmt.Sprintf("(%v)", strings.Join(andExpr, " AND "))
|
||||
}
|
||||
|
||||
// Var returns a placeholder for value.
|
||||
func (c *Cond) Var(value interface{}) string {
|
||||
return c.Args.Add(value)
|
||||
|
||||
+22
-21
@@ -9,27 +9,28 @@ import (
|
||||
|
||||
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) },
|
||||
"$$a <> $0": func() string { return newTestCond().NotEqual("$a", 123) },
|
||||
"$$b <> $0": func() string { return newTestCond().NE("$b", 123) },
|
||||
"$$a > $0": func() string { return newTestCond().GreaterThan("$a", 123) },
|
||||
"$$b > $0": func() string { return newTestCond().G("$b", 123) },
|
||||
"$$a >= $0": func() string { return newTestCond().GreaterEqualThan("$a", 123) },
|
||||
"$$b >= $0": func() string { return newTestCond().GE("$b", 123) },
|
||||
"$$a < $0": func() string { return newTestCond().LessThan("$a", 123) },
|
||||
"$$b < $0": func() string { return newTestCond().L("$b", 123) },
|
||||
"$$a <= $0": func() string { return newTestCond().LessEqualThan("$a", 123) },
|
||||
"$$b <= $0": func() string { return newTestCond().LE("$b", 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%") },
|
||||
"$$a NOT LIKE $0": func() string { return newTestCond().NotLike("$a", "%Huan%") },
|
||||
"$$a IS NULL": func() string { return newTestCond().IsNull("$a") },
|
||||
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },
|
||||
"$$a BETWEEN $0 AND $1": func() string { return newTestCond().Between("$a", 123, 456) },
|
||||
"$$a NOT BETWEEN $0 AND $1": func() string { return newTestCond().NotBetween("$a", 123, 456) },
|
||||
"(1 = 1 OR 2 = 2 OR 3 = 3)": func() string { return newTestCond().Or("1 = 1", "2 = 2", "3 = 3") },
|
||||
"$$a = $0": func() string { return newTestCond().Equal("$a", 123) },
|
||||
"$$b = $0": func() string { return newTestCond().E("$b", 123) },
|
||||
"$$a <> $0": func() string { return newTestCond().NotEqual("$a", 123) },
|
||||
"$$b <> $0": func() string { return newTestCond().NE("$b", 123) },
|
||||
"$$a > $0": func() string { return newTestCond().GreaterThan("$a", 123) },
|
||||
"$$b > $0": func() string { return newTestCond().G("$b", 123) },
|
||||
"$$a >= $0": func() string { return newTestCond().GreaterEqualThan("$a", 123) },
|
||||
"$$b >= $0": func() string { return newTestCond().GE("$b", 123) },
|
||||
"$$a < $0": func() string { return newTestCond().LessThan("$a", 123) },
|
||||
"$$b < $0": func() string { return newTestCond().L("$b", 123) },
|
||||
"$$a <= $0": func() string { return newTestCond().LessEqualThan("$a", 123) },
|
||||
"$$b <= $0": func() string { return newTestCond().LE("$b", 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%") },
|
||||
"$$a NOT LIKE $0": func() string { return newTestCond().NotLike("$a", "%Huan%") },
|
||||
"$$a IS NULL": func() string { return newTestCond().IsNull("$a") },
|
||||
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },
|
||||
"$$a BETWEEN $0 AND $1": func() string { return newTestCond().Between("$a", 123, 456) },
|
||||
"$$a NOT BETWEEN $0 AND $1": func() string { return newTestCond().NotBetween("$a", 123, 456) },
|
||||
"(1 = 1 OR 2 = 2 OR 3 = 3)": func() string { return newTestCond().Or("1 = 1", "2 = 2", "3 = 3") },
|
||||
"(1 = 1 AND 2 = 2 AND 3 = 3)": func() string { return newTestCond().And("1 = 1", "2 = 2", "3 = 3") },
|
||||
"$0": func() string { return newTestCond().Var(123) },
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user