wip: refactory log with zap
This commit is contained in:
@ -32,11 +32,11 @@ func New(uri string) (*gorm.DB, error) {
|
||||
switch ins.Scheme {
|
||||
case "sqlite":
|
||||
path := strings.TrimPrefix(uri, ins.Scheme+"://")
|
||||
log.Debug("db.New: type = %s, path = %s", ins.Scheme, path)
|
||||
log.Logger.Sugar().Debugf("db.New: type = %s, path = %s", ins.Scheme, path)
|
||||
tx, err = gorm.Open(sqlite.Open(path))
|
||||
case "mysql", "mariadb":
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?%s", username, password, ins.Host, ins.Path, ins.RawQuery)
|
||||
log.Debug("db.New: type = %s, dsn = %s", ins.Scheme, dsn)
|
||||
log.Logger.Sugar().Debugf("db.New: type = %s, dsn = %s", ins.Scheme, dsn)
|
||||
tx, err = gorm.Open(mysql.Open(dsn))
|
||||
case "pg", "postgres", "postgresql":
|
||||
opts := make([]string, 0)
|
||||
@ -44,7 +44,7 @@ func New(uri string) (*gorm.DB, error) {
|
||||
opts = append(opts, fmt.Sprintf("%s=%s", key, val))
|
||||
}
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s %s", ins.Hostname(), username, password, ins.Path, ins.Port(), strings.Join(opts, " "))
|
||||
log.Debug("db.New: type = %s, dsn = %s", ins.Scheme, dsn)
|
||||
log.Logger.Sugar().Debugf("db.New: type = %s, dsn = %s", ins.Scheme, dsn)
|
||||
tx, err = gorm.Open(postgres.Open(dsn))
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid database type(uri_scheme): %s", ins.Scheme)
|
||||
|
Reference in New Issue
Block a user