diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-30 10:47:08 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-30 10:47:08 -0400 |
commit | a6e12aaef6344fff43745baa755c6afa11935550 (patch) | |
tree | 85d6320a9917cdb7efdea39b4b85cf1c36aa5b52 /models/models.go | |
parent | 03cc39ea121e87febf4421d84e579770f635695c (diff) | |
download | gitea-a6e12aaef6344fff43745baa755c6afa11935550.tar.gz gitea-a6e12aaef6344fff43745baa755c6afa11935550.zip |
Fixing bug
Diffstat (limited to 'models/models.go')
-rw-r--r-- | models/models.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/models/models.go b/models/models.go index 825730c5a8..06533e45f9 100644 --- a/models/models.go +++ b/models/models.go @@ -17,7 +17,8 @@ import ( ) var ( - orm *xorm.Engine + orm *xorm.Engine + HasEngine bool DbCfg struct { Type, Host, Name, User, Pwd, Path, SslMode string @@ -34,6 +35,28 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } +func NewTestEngine(x *xorm.Engine) (err error) { + switch DbCfg.Type { + case "mysql": + x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", + DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) + case "postgres": + x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", + DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode)) + case "sqlite3": + os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) + x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + default: + return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) + } + if err != nil { + return fmt.Errorf("models.init(fail to conntect database): %v\n", err) + } + + return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch), + new(Action), new(Access), new(Issue), new(Comment)) +} + func SetEngine() (err error) { switch DbCfg.Type { case "mysql": |