代码拉取完成,页面将自动刷新
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}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。