diff --git a/engine_go1.15.go b/engine_go1.15.go new file mode 100644 index 00000000..add4d125 --- /dev/null +++ b/engine_go1.15.go @@ -0,0 +1,16 @@ +// +build go1.15 + +package xorm + +import ( + "time" +) + +// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle. +// +// Expired connections may be closed lazily before reuse. +// +// If d <= 0, connections are not closed due to a connection's idle time. +func (engine *Engine) SetConnMaxIdleTime(d time.Duration) { + engine.DB().SetConnMaxIdleTime(d) +} diff --git a/engine_group_go1.15.go b/engine_group_go1.15.go new file mode 100644 index 00000000..39394838 --- /dev/null +++ b/engine_group_go1.15.go @@ -0,0 +1,19 @@ +// +build go1.15 + +package xorm + +import ( + "time" +) + +// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle. +// +// Expired connections may be closed lazily before reuse. +// +// If d <= 0, connections are not closed due to a connection's idle time. +func (eg *EngineGroup) SetConnMaxIdleTime(d time.Duration) { + eg.Engine.SetConnMaxIdleTime(d) + for i := 0; i < len(eg.slaves); i++ { + eg.slaves[i].SetConnMaxIdleTime(d) + } +} diff --git a/engine_interface.go b/engine_interface.go new file mode 100644 index 00000000..3d55be0e --- /dev/null +++ b/engine_interface.go @@ -0,0 +1,72 @@ +// +build !go1.15 + +package xorm + +import ( + "context" + "database/sql" + "reflect" + "time" + + "xorm.io/xorm/caches" + "xorm.io/xorm/contexts" + "xorm.io/xorm/dialects" + "xorm.io/xorm/log" + "xorm.io/xorm/names" + "xorm.io/xorm/schemas" +) + +// EngineInterface defines the interface which Engine, EngineGroup will implementate. +type EngineInterface interface { + Interface + + Before(func(interface{})) *Session + Charset(charset string) *Session + ClearCache(...interface{}) error + Context(context.Context) *Session + CreateTables(...interface{}) error + DBMetas() ([]*schemas.Table, error) + Dialect() dialects.Dialect + DriverName() string + DropTables(...interface{}) error + DumpAllToFile(fp string, tp ...schemas.DBType) error + GetCacher(string) caches.Cacher + GetColumnMapper() names.Mapper + GetDefaultCacher() caches.Cacher + GetTableMapper() names.Mapper + GetTZDatabase() *time.Location + GetTZLocation() *time.Location + ImportFile(fp string) ([]sql.Result, error) + MapCacher(interface{}, caches.Cacher) error + NewSession() *Session + NoAutoTime() *Session + Quote(string) string + SetCacher(string, caches.Cacher) + SetConnMaxLifetime(time.Duration) + SetColumnMapper(names.Mapper) + SetDefaultCacher(caches.Cacher) + SetLogger(logger interface{}) + SetLogLevel(log.LogLevel) + SetMapper(names.Mapper) + SetMaxOpenConns(int) + SetMaxIdleConns(int) + SetQuotePolicy(dialects.QuotePolicy) + SetSchema(string) + SetTableMapper(names.Mapper) + SetTZDatabase(tz *time.Location) + SetTZLocation(tz *time.Location) + AddHook(hook contexts.Hook) + ShowSQL(show ...bool) + Sync(...interface{}) error + Sync2(...interface{}) error + StoreEngine(storeEngine string) *Session + TableInfo(bean interface{}) (*schemas.Table, error) + TableName(interface{}, ...bool) string + UnMapType(reflect.Type) + EnableSessionID(bool) +} + +var ( + _ EngineInterface = &Engine{} + _ EngineInterface = &EngineGroup{} +) diff --git a/engine_interface_go1.15.go b/engine_interface_go1.15.go new file mode 100644 index 00000000..da732968 --- /dev/null +++ b/engine_interface_go1.15.go @@ -0,0 +1,73 @@ +// +build go1.15 + +package xorm + +import ( + "context" + "database/sql" + "reflect" + "time" + + "xorm.io/xorm/caches" + "xorm.io/xorm/contexts" + "xorm.io/xorm/dialects" + "xorm.io/xorm/log" + "xorm.io/xorm/names" + "xorm.io/xorm/schemas" +) + +// EngineInterface defines the interface which Engine, EngineGroup will implementate. +type EngineInterface interface { + Interface + + Before(func(interface{})) *Session + Charset(charset string) *Session + ClearCache(...interface{}) error + Context(context.Context) *Session + CreateTables(...interface{}) error + DBMetas() ([]*schemas.Table, error) + Dialect() dialects.Dialect + DriverName() string + DropTables(...interface{}) error + DumpAllToFile(fp string, tp ...schemas.DBType) error + GetCacher(string) caches.Cacher + GetColumnMapper() names.Mapper + GetDefaultCacher() caches.Cacher + GetTableMapper() names.Mapper + GetTZDatabase() *time.Location + GetTZLocation() *time.Location + ImportFile(fp string) ([]sql.Result, error) + MapCacher(interface{}, caches.Cacher) error + NewSession() *Session + NoAutoTime() *Session + Quote(string) string + SetCacher(string, caches.Cacher) + SetConnMaxLifetime(time.Duration) + SetConnMaxIdleTime(time.Duration) // only go1.15 or higher + SetColumnMapper(names.Mapper) + SetDefaultCacher(caches.Cacher) + SetLogger(logger interface{}) + SetLogLevel(log.LogLevel) + SetMapper(names.Mapper) + SetMaxOpenConns(int) + SetMaxIdleConns(int) + SetQuotePolicy(dialects.QuotePolicy) + SetSchema(string) + SetTableMapper(names.Mapper) + SetTZDatabase(tz *time.Location) + SetTZLocation(tz *time.Location) + AddHook(hook contexts.Hook) + ShowSQL(show ...bool) + Sync(...interface{}) error + Sync2(...interface{}) error + StoreEngine(storeEngine string) *Session + TableInfo(bean interface{}) (*schemas.Table, error) + TableName(interface{}, ...bool) string + UnMapType(reflect.Type) + EnableSessionID(bool) +} + +var ( + _ EngineInterface = &Engine{} + _ EngineInterface = &EngineGroup{} +) diff --git a/interface.go b/interface.go index 6ad0577a..ce446144 100644 --- a/interface.go +++ b/interface.go @@ -5,17 +5,7 @@ package xorm import ( - "context" "database/sql" - "reflect" - "time" - - "xorm.io/xorm/caches" - "xorm.io/xorm/contexts" - "xorm.io/xorm/dialects" - "xorm.io/xorm/log" - "xorm.io/xorm/names" - "xorm.io/xorm/schemas" ) // Interface defines the interface which Engine, EngineGroup and Session will implementate. @@ -74,61 +64,4 @@ type Interface interface { Where(interface{}, ...interface{}) *Session } -// EngineInterface defines the interface which Engine, EngineGroup will implementate. -type EngineInterface interface { - Interface - - Before(func(interface{})) *Session - Charset(charset string) *Session - ClearCache(...interface{}) error - Context(context.Context) *Session - CreateTables(...interface{}) error - DBMetas() ([]*schemas.Table, error) - DBVersion() (*schemas.Version, error) - Dialect() dialects.Dialect - DriverName() string - DropTables(...interface{}) error - DumpAllToFile(fp string, tp ...schemas.DBType) error - GetCacher(string) caches.Cacher - GetColumnMapper() names.Mapper - GetDefaultCacher() caches.Cacher - GetTableMapper() names.Mapper - GetTZDatabase() *time.Location - GetTZLocation() *time.Location - ImportFile(fp string) ([]sql.Result, error) - MapCacher(interface{}, caches.Cacher) error - NewSession() *Session - NoAutoTime() *Session - Prepare() *Session - Quote(string) string - SetCacher(string, caches.Cacher) - SetConnMaxLifetime(time.Duration) - SetColumnMapper(names.Mapper) - SetTagIdentifier(string) - SetDefaultCacher(caches.Cacher) - SetLogger(logger interface{}) - SetLogLevel(log.LogLevel) - SetMapper(names.Mapper) - SetMaxOpenConns(int) - SetMaxIdleConns(int) - SetQuotePolicy(dialects.QuotePolicy) - SetSchema(string) - SetTableMapper(names.Mapper) - SetTZDatabase(tz *time.Location) - SetTZLocation(tz *time.Location) - AddHook(hook contexts.Hook) - ShowSQL(show ...bool) - Sync(...interface{}) error - Sync2(...interface{}) error - StoreEngine(storeEngine string) *Session - TableInfo(bean interface{}) (*schemas.Table, error) - TableName(interface{}, ...bool) string - UnMapType(reflect.Type) - EnableSessionID(bool) -} - -var ( - _ Interface = &Session{} - _ EngineInterface = &Engine{} - _ EngineInterface = &EngineGroup{} -) +var _ Interface = &Session{}