You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.go 1.4 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "os"
  8. _ "github.com/go-sql-driver/mysql"
  9. "github.com/lunny/xorm"
  10. "github.com/gogits/gogs/utils"
  11. "github.com/gogits/gogs/utils/log"
  12. )
  13. var (
  14. orm *xorm.Engine
  15. repoRootPath string
  16. )
  17. type Members struct {
  18. Id int64
  19. OrgId int64 `xorm:"unique(s) index"`
  20. UserId int64 `xorm:"unique(s)"`
  21. }
  22. type Issue struct {
  23. Id int64
  24. RepoId int64 `xorm:"index"`
  25. PosterId int64
  26. }
  27. type PullRequest struct {
  28. Id int64
  29. }
  30. type Comment struct {
  31. Id int64
  32. }
  33. func setEngine() {
  34. dbType := utils.Cfg.MustValue("database", "DB_TYPE")
  35. dbHost := utils.Cfg.MustValue("database", "HOST")
  36. dbName := utils.Cfg.MustValue("database", "NAME")
  37. dbUser := utils.Cfg.MustValue("database", "USER")
  38. dbPwd := utils.Cfg.MustValue("database", "PASSWD")
  39. var err error
  40. switch dbType {
  41. case "mysql":
  42. orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%v@%v/%v?charset=utf8",
  43. dbUser, dbPwd, dbHost, dbName))
  44. default:
  45. log.Critical("Unknown database type: %s", dbType)
  46. os.Exit(2)
  47. }
  48. if err != nil {
  49. log.Critical("models.init -> Conntect database: %s", dbType)
  50. os.Exit(2)
  51. }
  52. //x.ShowDebug = true
  53. orm.ShowErr = true
  54. //x.ShowSQL = true
  55. log.Trace("Initialized database -> %s", dbName)
  56. }
  57. func init() {
  58. setEngine()
  59. orm.Sync(new(User))
  60. }

No Description