|
|
@ -7,6 +7,7 @@ package models |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
"path" |
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
_ "github.com/lib/pq" |
|
|
|
_ "github.com/lib/pq" |
|
|
@ -23,6 +24,7 @@ func setEngine() { |
|
|
|
dbName := base.Cfg.MustValue("database", "NAME") |
|
|
|
dbName := base.Cfg.MustValue("database", "NAME") |
|
|
|
dbUser := base.Cfg.MustValue("database", "USER") |
|
|
|
dbUser := base.Cfg.MustValue("database", "USER") |
|
|
|
dbPwd := base.Cfg.MustValue("database", "PASSWD") |
|
|
|
dbPwd := base.Cfg.MustValue("database", "PASSWD") |
|
|
|
|
|
|
|
dbPath := base.Cfg.MustValue("database", "PATH", "data/gogs.db") |
|
|
|
sslMode := base.Cfg.MustValue("database", "SSL_MODE") |
|
|
|
sslMode := base.Cfg.MustValue("database", "SSL_MODE") |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
var err error |
|
|
@ -33,6 +35,9 @@ func setEngine() { |
|
|
|
case "postgres": |
|
|
|
case "postgres": |
|
|
|
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", |
|
|
|
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", |
|
|
|
dbUser, dbPwd, dbName, sslMode)) |
|
|
|
dbUser, dbPwd, dbName, sslMode)) |
|
|
|
|
|
|
|
case "sqlite3": |
|
|
|
|
|
|
|
os.MkdirAll(path.Dir(dbPath), os.ModePerm) |
|
|
|
|
|
|
|
orm, err = xorm.NewEngine("sqlite3", dbPath) |
|
|
|
default: |
|
|
|
default: |
|
|
|
fmt.Printf("Unknown database type: %s\n", dbType) |
|
|
|
fmt.Printf("Unknown database type: %s\n", dbType) |
|
|
|
os.Exit(2) |
|
|
|
os.Exit(2) |
|
|
|