mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
add struct support for where condition statement og gdb
This commit is contained in:
parent
ac9be6134b
commit
3120f24553
@ -396,6 +396,15 @@ func handlerSliceArguments(query string, args []interface{}) (newQuery string, n
|
||||
}
|
||||
return s
|
||||
})
|
||||
|
||||
// Special struct handling.
|
||||
case reflect.Struct:
|
||||
if v, ok := arg.(apiString); ok {
|
||||
newArgs = append(newArgs, v.String())
|
||||
} else {
|
||||
newArgs = append(newArgs, arg)
|
||||
}
|
||||
|
||||
default:
|
||||
newArgs = append(newArgs, arg)
|
||||
}
|
||||
|
@ -409,6 +409,36 @@ func Test_Model_FindAll(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_FindAll_GTime(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.Case(t, func() {
|
||||
result, err := db.Table(table).FindAll("create_time < ?", gtime.NewFromStr("2000-01-01 00:00:00"))
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(result), 0)
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
result, err := db.Table(table).FindAll("create_time > ?", gtime.NewFromStr("2000-01-01 00:00:00"))
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(result), SIZE)
|
||||
})
|
||||
|
||||
gtest.Case(t, func() {
|
||||
v := g.NewVar("2000-01-01 00:00:00")
|
||||
result, err := db.Table(table).FindAll("create_time < ?", v)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(result), 0)
|
||||
})
|
||||
|
||||
gtest.Case(t, func() {
|
||||
v := g.NewVar("2000-01-01 00:00:00")
|
||||
result, err := db.Table(table).FindAll("create_time > ?", v)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(result), SIZE)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_One(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
Loading…
Reference in New Issue
Block a user