|
|
@ -61,6 +61,10 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newEngine(driverName, dataSourceName, dialect, db) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newEngine(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) { |
|
|
|
cacherMgr := caches.NewManager() |
|
|
|
cacherMgr := caches.NewManager() |
|
|
|
mapper := names.NewCacheMapper(new(names.SnakeMapper)) |
|
|
|
mapper := names.NewCacheMapper(new(names.SnakeMapper)) |
|
|
|
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr) |
|
|
|
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr) |
|
|
@ -88,7 +92,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) { |
|
|
|
engine.SetLogger(log.NewLoggerAdapter(logger)) |
|
|
|
engine.SetLogger(log.NewLoggerAdapter(logger)) |
|
|
|
|
|
|
|
|
|
|
|
runtime.SetFinalizer(engine, func(engine *Engine) { |
|
|
|
runtime.SetFinalizer(engine, func(engine *Engine) { |
|
|
|
engine.Close() |
|
|
|
_ = engine.Close() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return engine, nil |
|
|
|
return engine, nil |
|
|
@ -101,6 +105,14 @@ func NewEngineWithParams(driverName string, dataSourceName string, params map[st |
|
|
|
return engine, err |
|
|
|
return engine, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewEngineWithDialectAndDB new a db manager according to the parameter.
|
|
|
|
|
|
|
|
// If you do not want to use your own dialect or db, please use NewEngine.
|
|
|
|
|
|
|
|
// For creating dialect, you can call dialects.OpenDialect. And, for creating db,
|
|
|
|
|
|
|
|
// you can call core.Open or core.FromDB.
|
|
|
|
|
|
|
|
func NewEngineWithDialectAndDB(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) { |
|
|
|
|
|
|
|
return newEngine(driverName, dataSourceName, dialect, db) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// EnableSessionID if enable session id
|
|
|
|
// EnableSessionID if enable session id
|
|
|
|
func (engine *Engine) EnableSessionID(enable bool) { |
|
|
|
func (engine *Engine) EnableSessionID(enable bool) { |
|
|
|
engine.logSessionID = enable |
|
|
|
engine.logSessionID = enable |
|
|
@ -347,13 +359,16 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error { |
|
|
|
var seq int |
|
|
|
var seq int |
|
|
|
for _, index := range indexes { |
|
|
|
for _, index := range indexes { |
|
|
|
for _, name := range index.Cols { |
|
|
|
for _, name := range index.Cols { |
|
|
|
parts := strings.Split(name, " ") |
|
|
|
parts := strings.Split(strings.TrimSpace(name), " ") |
|
|
|
if len(parts) > 1 { |
|
|
|
if len(parts) > 1 { |
|
|
|
if parts[1] == "DESC" { |
|
|
|
if parts[1] == "DESC" { |
|
|
|
seq = 1 |
|
|
|
seq = 1 |
|
|
|
|
|
|
|
} else if parts[1] == "ASC" { |
|
|
|
|
|
|
|
seq = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if col := table.GetColumn(parts[0]); col != nil { |
|
|
|
var colName = strings.Trim(parts[0], `"`) |
|
|
|
|
|
|
|
if col := table.GetColumn(colName); col != nil { |
|
|
|
col.Indexes[index.Name] = index.Type |
|
|
|
col.Indexes[index.Name] = index.Type |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq()) |
|
|
|
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq()) |
|
|
|