summaryrefslogtreecommitdiffstats
path: root/models/models.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/models.go')
-rw-r--r--models/models.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/models/models.go b/models/models.go
index 3a83929a77..0b02de54d4 100644
--- a/models/models.go
+++ b/models/models.go
@@ -13,9 +13,12 @@ import (
"path"
"strings"
+ // Needed for the MySQL driver
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
+
+ // Needed for the Postgresql driver
_ "github.com/lib/pq"
"code.gitea.io/gitea/models/migrations"
@@ -45,16 +48,22 @@ func sessionRelease(sess *xorm.Session) {
}
var (
- x *xorm.Engine
- tables []interface{}
+ x *xorm.Engine
+ tables []interface{}
+
+ // HasEngine specifies if we have a xorm.Engine
HasEngine bool
+ // DbCfg holds the database settings
DbCfg struct {
Type, Host, Name, User, Passwd, Path, SSLMode string
}
+ // EnableSQLite3 use SQLite3
EnableSQLite3 bool
- EnableTiDB bool
+
+ // EnableTiDB enable TiDB
+ EnableTiDB bool
)
func init() {
@@ -69,12 +78,13 @@ func init() {
new(Team), new(OrgUser), new(TeamUser), new(TeamRepo),
new(Notice), new(EmailAddress))
- gonicNames := []string{"SSL"}
+ gonicNames := []string{"SSL", "UID"}
for _, name := range gonicNames {
core.LintGonicMapper[name] = true
}
}
+// LoadConfigs loads the database settings
func LoadConfigs() {
sec := setting.Cfg.Section("database")
DbCfg.Type = sec.Key("DB_TYPE").String()
@@ -115,7 +125,7 @@ func parsePostgreSQLHostPort(info string) (string, string) {
func getEngine() (*xorm.Engine, error) {
connStr := ""
- var Param string = "?"
+ var Param = "?"
if strings.Contains(DbCfg.Name, Param) {
Param = "&"
}
@@ -159,6 +169,7 @@ func getEngine() (*xorm.Engine, error) {
return xorm.NewEngine(DbCfg.Type, connStr)
}
+// NewTestEngine sets a new test xorm.Engine
func NewTestEngine(x *xorm.Engine) (err error) {
x, err = getEngine()
if err != nil {
@@ -169,6 +180,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
return x.StoreEngine("InnoDB").Sync2(tables...)
}
+// SetEngine sets the xorm.Engine
func SetEngine() (err error) {
x, err = getEngine()
if err != nil {
@@ -191,6 +203,7 @@ func SetEngine() (err error) {
return nil
}
+// NewEngine initializes a new xorm.Engine
func NewEngine() (err error) {
if err = SetEngine(); err != nil {
return err
@@ -211,6 +224,7 @@ func NewEngine() (err error) {
return nil
}
+// Statistic contains the database statistics
type Statistic struct {
Counter struct {
User, Org, PublicKey,
@@ -222,6 +236,7 @@ type Statistic struct {
}
}
+// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
stats.Counter.User = CountUsers()
stats.Counter.Org = CountOrganizations()
@@ -248,6 +263,7 @@ func GetStatistic() (stats Statistic) {
return
}
+// Ping tests if database is alive
func Ping() error {
return x.Ping()
}