add struct support for where condition statement og gdb

This commit is contained in:
John 2020-02-07 19:44:11 +08:00
parent ac9be6134b
commit 3120f24553
2 changed files with 39 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)