1 Star 0 Fork 0

linxing/youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dialector.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2024-01-29 17:39 . rename package
package database
import (
"fmt"
"gitee.com/linxing_3/youye-core/sdk/config"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func opens(driver string) func(string) gorm.Dialector {
switch driver {
case config.MySQL:
return mysql.Open
case config.Postgres:
return postgres.Open
case config.SQLite:
return sqlite.Open
}
return nil
}
// NewDialect build dialect
func NewDialect(conf config.Database, conn gorm.ConnPool) (gorm.Dialector, error) {
var dialect gorm.Dialector
switch conf.Driver {
case config.MySQL:
dialect = newMySQLDialect(conn)
case config.Postgres:
dialect = newPostgresDialect(conn)
case config.SQLite:
dialect = newSQLiteDialect(conn)
default:
return nil, fmt.Errorf("unsupported database driver: %s", conf.Driver)
}
return dialect, nil
}
// newMySQLDialect build mysql dialect
func newMySQLDialect(conn gorm.ConnPool) gorm.Dialector {
return mysql.New(mysql.Config{Conn: conn})
}
// newPostgresDialect build postgres dialect
func newPostgresDialect(conn gorm.ConnPool) gorm.Dialector {
return postgres.New(postgres.Config{Conn: conn})
}
// newSQLiteDialect build sqlite dialect
func newSQLiteDialect(conn gorm.ConnPool) gorm.Dialector {
return sqlite.Dialector{Conn: conn}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202406121004

搜索帮助