Test update with GormValuer

This commit is contained in:
Jinzhu 2020-08-27 18:42:40 +08:00
parent 7a90496701
commit cd54dddd94
2 changed files with 16 additions and 5 deletions

View File

@ -9,7 +9,7 @@ require (
gorm.io/driver/mysql v0.3.2 gorm.io/driver/mysql v0.3.2
gorm.io/driver/postgres v0.2.9 gorm.io/driver/postgres v0.2.9
gorm.io/driver/sqlite v1.0.9 gorm.io/driver/sqlite v1.0.9
gorm.io/driver/sqlserver v0.2.7 gorm.io/driver/sqlserver v0.2.8
gorm.io/gorm v0.2.36 gorm.io/gorm v0.2.36
) )

View File

@ -314,10 +314,6 @@ type Point struct {
X, Y int X, Y int
} }
func (point *Point) Scan(v interface{}) error {
return nil
}
func (point Point) GormDataType() string { func (point Point) GormDataType() string {
return "geo" return "geo"
} }
@ -379,4 +375,19 @@ func TestGORMValuer(t *testing.T) {
if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) { if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) {
t.Errorf("generated vars is not equal, got %v", stmt.Vars) t.Errorf("generated vars is not equal, got %v", stmt.Vars)
} }
stmt = dryRunDB.Session(&gorm.Session{
AllowGlobalUpdate: true,
}).Model(&UserWithPoint{}).Updates(UserWithPoint{
Name: "jinzhu",
Point: Point{X: 100, Y: 100},
}).Statement
if !regexp.MustCompile(`UPDATE .user_with_points. SET .name.=.+,.point.=ST_PointFromText\(.+\)`).MatchString(stmt.SQL.String()) {
t.Errorf("insert with sql.Expr, but got %v", stmt.SQL.String())
}
if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) {
t.Errorf("generated vars is not equal, got %v", stmt.Vars)
}
} }