adding support of slice parameters for gdb.Model.Where

This commit is contained in:
John
2019-07-09 08:40:28 +08:00
parent 691baf5c16
commit 8ff21d6936
3 changed files with 29 additions and 2 deletions

View File

@ -625,6 +625,15 @@ func TestModel_Where(t *testing.T) {
gtest.AssertGT(len(result), 0)
gtest.Assert(result["id"].Int(), 3)
})
// slice parameter
gtest.Case(t, func() {
result, err := db.Table("user").Where("id=? and nickname=?", g.Slice{3, "T3"}).One()
if err != nil {
gtest.Fatal(err)
}
gtest.AssertGT(len(result), 0)
gtest.Assert(result["id"].Int(), 3)
})
gtest.Case(t, func() {
result, err := db.Table("user").Where("id", 3).One()
if err != nil {

View File

@ -7,11 +7,12 @@
package gredis_test
import (
"testing"
"time"
"github.com/gogf/gf/g/database/gredis"
"github.com/gogf/gf/g/test/gtest"
redis2 "github.com/gogf/gf/third/github.com/gomodule/redigo/redis"
"testing"
"time"
)
var (

View File

@ -0,0 +1,17 @@
package main
import (
"github.com/gogf/gf/g"
)
func main() {
db := g.DB()
conditions := g.Map{
"nickname like ?": "%T%",
"id between ? and ?": g.Slice{1, 3},
"id >= ?": 1,
"create_time > ?": 0,
"id in(?)": g.Slice{1, 2, 3},
}
db.Table("user").Where(conditions).OrderBy("id asc").All()
}