Skip to content

Commit

Permalink
Merge pull request go-gorm#487 from xsxnet/master
Browse files Browse the repository at this point in the history
fix: rename template variable name to avoid naming conflicts with package name
  • Loading branch information
tr1v3r authored Jun 22, 2022
2 parents 54c9342 + b41c86a commit 2cc53d6
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ func init() {
func Test_{{.NewStructName}}Query(t *testing.T) {
{{.NewStructName}} := new{{.StructName}}(db)
{{.NewStructName}} = *{{.NewStructName}}.As({{.NewStructName}}.TableName())
do := {{.NewStructName}}.WithContext(context.Background()).Debug()
_do := {{.NewStructName}}.WithContext(context.Background()).Debug()
primaryKey := field.NewString({{.NewStructName}}.TableName(), clause.PrimaryKey)
_, err := do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <{{.TableName}}> fail:", err)
return
Expand All @@ -275,105 +275,105 @@ func Test_{{.NewStructName}}Query(t *testing.T) {
t.Error("GetFieldByName(\"\") from {{.NewStructName}} success")
}
err = do.Create(&{{.StructInfo.Package}}.{{.StructName}}{})
err = _do.Create(&{{.StructInfo.Package}}.{{.StructName}}{})
if err != nil {
t.Error("create item in table <{{.TableName}}> fail:", err)
}
err = do.Save(&{{.StructInfo.Package}}.{{.StructName}}{})
err = _do.Save(&{{.StructInfo.Package}}.{{.StructName}}{})
if err != nil {
t.Error("create item in table <{{.TableName}}> fail:", err)
}
err = do.CreateInBatches([]*{{.StructInfo.Package}}.{{.StructName}}{ {}, {} }, 10)
err = _do.CreateInBatches([]*{{.StructInfo.Package}}.{{.StructName}}{ {}, {} }, 10)
if err != nil {
t.Error("create item in table <{{.TableName}}> fail:", err)
}
_, err = do.Select({{.NewStructName}}.ALL).Take()
_, err = _do.Select({{.NewStructName}}.ALL).Take()
if err != nil {
t.Error("Take() on table <{{.TableName}}> fail:", err)
}
_, err = do.First()
_, err = _do.First()
if err != nil {
t.Error("First() on table <{{.TableName}}> fail:", err)
}
_, err = do.Last()
_, err = _do.Last()
if err != nil {
t.Error("First() on table <{{.TableName}}> fail:", err)
}
_, err = do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <{{.TableName}}> fail:", err)
}
err = do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*{{.StructInfo.Package}}.{{.StructName}}{}, 10, func(tx gen.Dao, batch int) error { return nil })
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*{{.StructInfo.Package}}.{{.StructName}}{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <{{.TableName}}> fail:", err)
}
_, err = do.Select({{.NewStructName}}.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
_, err = _do.Select({{.NewStructName}}.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <{{.TableName}}> fail:", err)
}
_, err = do.Distinct(primaryKey).Take()
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <{{.TableName}}> fail:", err)
}
_, err = do.Select({{.NewStructName}}.ALL).Omit(primaryKey).Take()
_, err = _do.Select({{.NewStructName}}.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <{{.TableName}}> fail:", err)
}
_, err = do.Group(primaryKey).Find()
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <{{.TableName}}> fail:", err)
}
_, err = do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <{{.TableName}}> fail:", err)
}
_, _, err = do.FindByPage(0, 1)
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <{{.TableName}}> fail:", err)
}
_, err = do.ScanByPage(&{{.StructInfo.Package}}.{{.StructName}}{}, 0, 1)
_, err = _do.ScanByPage(&{{.StructInfo.Package}}.{{.StructName}}{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <{{.TableName}}> fail:", err)
}
_, err = do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <{{.TableName}}> fail:", err)
}
_, err = do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <{{.TableName}}> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey)
err = do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <{{.TableName}}> fail:", err)
}
err = do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <{{.TableName}}> fail:", err)
}
_, err = do.Not().Or().Clauses().Take()
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <{{.TableName}}> fail:", err)
}
Expand Down

0 comments on commit 2cc53d6

Please sign in to comment.