Skip to content

Commit

Permalink
backend postgresql support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmin authored and ouqiang committed Jul 11, 2018
1 parent c40ef9a commit 45662b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion internal/models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
"github.com/ouqiang/gocron/internal/modules/app"
Expand Down Expand Up @@ -97,7 +98,7 @@ func CreateTmpDb(setting *setting.Setting) (*xorm.Engine, error) {
return xorm.NewEngine(setting.Db.Engine, dsn)
}

// 获取数据库引擎DSN mysql,sqlite
// 获取数据库引擎DSN mysql,sqlite,postgres
func getDbEngineDSN(setting *setting.Setting) string {
engine := strings.ToLower(setting.Db.Engine)
dsn := ""
Expand All @@ -110,6 +111,13 @@ func getDbEngineDSN(setting *setting.Setting) string {
setting.Db.Port,
setting.Db.Database,
setting.Db.Charset)
case "postgres":
dsn = fmt.Sprintf("user=%s password=%s host=%s port=%d dbname=%s sslmode=disable",
setting.Db.User,
setting.Db.Password,
setting.Db.Host,
setting.Db.Port,
setting.Db.Database)
}

return dsn
Expand Down
3 changes: 2 additions & 1 deletion internal/routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// 系统安装

type InstallForm struct {
DbType string `binding:"In(mysql)"`
DbType string `binding:"In(mysql,postgres)"`
DbHost string `binding:"Required;MaxSize(50)"`
DbPort int `binding:"Required;Range(1,65535)"`
DbUsername string `binding:"Required;MaxSize(50)"`
Expand Down Expand Up @@ -141,6 +141,7 @@ func testDbConnection(form InstallForm) error {
s.Db.Port = form.DbPort
s.Db.User = form.DbUsername
s.Db.Password = form.DbPassword
s.Db.Database = form.DbName
s.Db.Charset = "utf8"
db, err := models.CreateTmpDb(&s)
if err != nil {
Expand Down

0 comments on commit 45662b1

Please sign in to comment.