-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_db.go
59 lines (51 loc) · 1.46 KB
/
config_db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gobatis
type DataSource struct {
DataSource string `yaml:"datasource"`
DriverName string `yaml:"driverName"`
DataSourceName string `yaml:"dataSourceName"`
MaxLifeTime int `yaml:"maxLifeTime"`
MaxOpenConns int `yaml:"maxOpenConns"`
MaxIdleConns int `yaml:"maxIdleConns"`
}
// NewDataSource new data source
func NewDataSource(dataSource string, driverName string, dataSourceName string) *DataSource {
return &DataSource{
DataSource: dataSource,
DriverName: driverName,
DataSourceName: dataSourceName,
}
}
// NewDataSource_ new data source
func NewDataSource_(dataSource string, driverName string, dataSourceName string,
maxLifeTime int, maxOpenConns int, maxIdleConns int) *DataSource {
return &DataSource{
DataSource: dataSource,
DriverName: driverName,
DataSourceName: dataSourceName,
MaxLifeTime: maxLifeTime,
MaxOpenConns: maxOpenConns,
MaxIdleConns: maxIdleConns,
}
}
type DBConfig struct {
DB []*DataSource `yaml:"db"`
ShowSQL bool `yaml:"showSQL"`
Mappers []string `yaml:"mappers"`
db map[string]*GoBatisDB
dbMap map[string]*DataSource
}
func (this *DBConfig) getDataSourceByName(datasource string) *DataSource {
if this.dbMap == nil {
this.dbMap = make(map[string]*DataSource)
}
if v, ok := this.dbMap[datasource]; ok {
return v
}
for _, v := range this.DB {
if v.DataSource == datasource {
this.dbMap[datasource] = v
return v
}
}
return nil
}