1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
def.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-09-22 18:49 . refactor datasource logic
package datasource
import (
"database/sql"
"gitee.com/kristas/booting-go/framework/core/bean"
"reflect"
)
type Datasource interface {
bean.Bean
Tag() string
GetType() string
GetHost() string
GetDatabase() string
GetUsername() string
GetPassword() string
GetTunnel() string
GetConnMaxLifeTime() int64
GetConnMaxIdleTime() int64
GetMaxIdleConns() int
GetMaxOpenConns() int
IsLazyFetch() bool
}
type Config struct {
bean.Component
prefix string
Type string `yaml:"type"`
Host string `yaml:"host"`
Database string `yaml:"database"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Tunnel string `yaml:"tunnel"`
ConnMaxLifeTime int64 `yaml:"max_life_time"`
ConnMaxIdleTime int64 `yaml:"max_idle_time"`
MaxIdleConns int `yaml:"max_idle_conn"`
MaxOpenConns int `yaml:"max_open_conn"`
LazyFetch bool `yaml:"lazy_fetch"`
}
func (c *Config) Prefix() string {
if c.prefix == "" {
return "application.datasource"
}
return c.prefix
}
type DataBaseConnectionHandler func(d *Starter, configure Datasource) (*sql.DB, error)
type ORMUpgrader interface {
bean.Bean
UpgradeType() reflect.Type
Upgrade(wrapper Wrapper) (interface{}, error)
}
type Wrapper interface {
DB() *sql.DB
Configure() Datasource
}
func newDatasourceWrapper(DB *sql.DB, configure Datasource) Wrapper {
return &defaultWrapper{
db: DB,
configure: configure,
}
}
type defaultWrapper struct {
db *sql.DB
configure Datasource
}
func (d *defaultWrapper) DB() *sql.DB {
return d.db
}
func (d *defaultWrapper) Configure() Datasource {
return d.configure
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.3.8

搜索帮助