From c61b902538e8e4b2bb83136f190e044a6bbcdd9b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 22 Mar 2020 23:12:55 +0800 Subject: Upgrade xorm to v1.0.0 (#10646) * Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag --- models/models.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'models/models.go') diff --git a/models/models.go b/models/models.go index 088445590f..08c7780317 100644 --- a/models/models.go +++ b/models/models.go @@ -15,8 +15,9 @@ import ( // Needed for the MySQL driver _ "github.com/go-sql-driver/mysql" - "xorm.io/core" "xorm.io/xorm" + "xorm.io/xorm/names" + "xorm.io/xorm/schemas" // Needed for the Postgresql driver _ "github.com/lib/pq" @@ -127,7 +128,7 @@ func init() { gonicNames := []string{"SSL", "UID"} for _, name := range gonicNames { - core.LintGonicMapper[name] = true + names.LintGonicMapper[name] = true } } @@ -152,8 +153,7 @@ func NewTestEngine(x *xorm.Engine) (err error) { return fmt.Errorf("Connect to database: %v", err) } - x.ShowExecTime(true) - x.SetMapper(core.GonicMapper{}) + x.SetMapper(names.GonicMapper{}) x.SetLogger(NewXORMLogger(!setting.ProdMode)) x.ShowSQL(!setting.ProdMode) return x.StoreEngine("InnoDB").Sync2(tables...) @@ -166,8 +166,7 @@ func SetEngine() (err error) { return fmt.Errorf("Failed to connect to database: %v", err) } - x.ShowExecTime(true) - x.SetMapper(core.GonicMapper{}) + x.SetMapper(names.GonicMapper{}) // WARNING: for serv command, MUST remove the output to os.stdout, // so use log file to instead print to stdout. x.SetLogger(NewXORMLogger(setting.Database.LogSQL)) @@ -249,21 +248,26 @@ func Ping() error { // DumpDatabase dumps all data from database according the special database SQL syntax to file system. func DumpDatabase(filePath string, dbType string) error { - var tbs []*core.Table + var tbs []*schemas.Table for _, t := range tables { - t := x.TableInfo(t) - t.Table.Name = t.Name - tbs = append(tbs, t.Table) + t, err := x.TableInfo(t) + if err != nil { + return err + } + tbs = append(tbs, t) } if len(dbType) > 0 { - return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType)) + return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType)) } return x.DumpTablesToFile(tbs, filePath) } // MaxBatchInsertSize returns the table's max batch insert size func MaxBatchInsertSize(bean interface{}) int { - t := x.TableInfo(bean) + t, err := x.TableInfo(bean) + if err != nil { + return 50 + } return 999 / len(t.ColumnsSeq()) } -- cgit v1.2.3