package orm

import "fmt"

type Config struct {
	Driver   string `json:"driver"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Name     string `json:"name"`
	User     string `json:"user"`
	Password string `json:"password"`
	Path     string `json:"path"`
}

func ParseDSN(cfg *Config) string {
	if cfg.Driver == "sqlite3" {
		return cfg.Path
	} else if cfg.Driver == "mysql" {
		return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
			cfg.User,
			cfg.Password,
			cfg.Host,
			cfg.Port,
			cfg.Name)
	} else if cfg.Driver == "postgres" {
		return fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s",
			cfg.Host,
			cfg.Port,
			cfg.User,
			cfg.Name,
			cfg.Password)
	}
	return ""
}
