mirror of https://github.com/status-im/fathom.git
don't parse database driver from URL to also support mysql and sqlite.
This commit is contained in:
parent
8f4a34282e
commit
4ecaff85ac
|
@ -1,5 +1,4 @@
|
|||
FATHOM_DEBUG=true
|
||||
FATHOM_DATABASE_URL=""
|
||||
FATHOM_DATABASE_DRIVER="sqlite3"
|
||||
FATHOM_DATABASE_NAME="./fathom.db"
|
||||
FATHOM_DATABASE_USER=""
|
||||
|
|
|
@ -2,9 +2,9 @@ package config
|
|||
|
||||
import (
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"net/url"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
|
@ -54,11 +54,10 @@ func Parse() *Config {
|
|||
}
|
||||
|
||||
if cfg.Database.URL != "" {
|
||||
u, err := url.Parse(cfg.Database.URL)
|
||||
_, err := url.Parse(cfg.Database.URL)
|
||||
if err != nil {
|
||||
log.Fatalf("Error parsing DATABASE_URL from environment: %s", err)
|
||||
}
|
||||
cfg.Database.Driver = u.Scheme
|
||||
}
|
||||
|
||||
// alias sqlite to sqlite3
|
||||
|
|
|
@ -18,11 +18,15 @@ type Config struct {
|
|||
func (c *Config) DSN() string {
|
||||
var dsn string
|
||||
|
||||
// if FATHOM_DATABASE_URL was set, use that
|
||||
// this relies on the user to set the appropriate parameters, eg ?parseTime=true when using MySQL
|
||||
if c.URL != "" {
|
||||
return c.URL
|
||||
}
|
||||
|
||||
// otherwise, generate from individual fields
|
||||
switch c.Driver {
|
||||
case "postgres":
|
||||
if c.URL != "" {
|
||||
dsn = c.URL
|
||||
} else {
|
||||
params := map[string]string{
|
||||
"host": c.Host,
|
||||
"dbname": c.Name,
|
||||
|
@ -38,8 +42,8 @@ func (c *Config) DSN() string {
|
|||
|
||||
dsn = dsn + k + "=" + v + " "
|
||||
}
|
||||
|
||||
dsn = strings.TrimSpace(dsn)
|
||||
}
|
||||
case "mysql":
|
||||
mc := mysql.NewConfig()
|
||||
mc.User = c.User
|
||||
|
|
Loading…
Reference in New Issue