Browse Source

Upgrade xorm to v1.0.0 (#10646)

* Upgrade xorm to v1.0.0

* small nit

* Fix tests

* Update xorm

* Update xorm

* fix go.sum

* fix test

* Fix bug when dump

* Fix bug

* update xorm to latest

* Fix migration test

* update xorm to latest

* Fix import order

* Use xorm tag
mj
Lunny Xiao 3 years ago
committed by GitHub
parent
commit
c61b902538
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      go.mod
  2. 10
      go.sum
  3. 7
      models/access.go
  4. 3
      models/list_options.go
  5. 18
      models/log.go
  6. 20
      models/login_source.go
  7. 24
      models/migrations/v110.go
  8. 9
      models/migrations/v81.go
  9. 28
      models/models.go
  10. 12
      models/org_team.go
  11. 6
      models/repo.go
  12. 4
      models/repo_unit.go
  13. 2
      models/ssh_key.go
  14. 3
      models/test_fixtures.go
  15. 4
      models/unit_tests.go
  16. 6
      routers/admin/auths.go
  17. 19
      vendor/modules.txt
  18. 71
      vendor/xorm.io/builder/.drone.yml
  19. 1
      vendor/xorm.io/builder/.gitignore
  20. 60
      vendor/xorm.io/builder/builder.go
  21. 2
      vendor/xorm.io/builder/builder_insert.go
  22. 9
      vendor/xorm.io/builder/builder_limit.go
  23. 2
      vendor/xorm.io/builder/builder_select.go
  24. 14
      vendor/xorm.io/builder/builder_set_operations.go
  25. 4
      vendor/xorm.io/builder/builder_update.go
  26. 4
      vendor/xorm.io/builder/cond_eq.go
  27. 2
      vendor/xorm.io/builder/go.mod
  28. 4
      vendor/xorm.io/builder/go.sum
  29. 9
      vendor/xorm.io/builder/sql.go
  30. 33
      vendor/xorm.io/core/.drone.yml
  31. 1
      vendor/xorm.io/core/.gitignore
  32. 27
      vendor/xorm.io/core/LICENSE
  33. 118
      vendor/xorm.io/core/README.md
  34. 1
      vendor/xorm.io/core/benchmark.sh
  35. 327
      vendor/xorm.io/core/dialect.go
  36. 31
      vendor/xorm.io/core/driver.go
  37. 93
      vendor/xorm.io/core/filter.go
  38. 8
      vendor/xorm.io/core/go.mod
  39. 20
      vendor/xorm.io/core/go.sum
  40. 37
      vendor/xorm.io/core/ilogger.go
  41. 53
      vendor/xorm.io/xorm/.changelog.yml
  42. 155
      vendor/xorm.io/xorm/.drone.yml
  43. 3
      vendor/xorm.io/xorm/.gitignore
  44. 25
      vendor/xorm.io/xorm/.revive.toml
  45. 173
      vendor/xorm.io/xorm/CHANGELOG.md
  46. 41
      vendor/xorm.io/xorm/CONTRIBUTING.md
  47. 214
      vendor/xorm.io/xorm/Makefile
  48. 67
      vendor/xorm.io/xorm/README.md
  49. 82
      vendor/xorm.io/xorm/README_CN.md
  50. 16
      vendor/xorm.io/xorm/caches/cache.go
  51. 58
      vendor/xorm.io/xorm/caches/encode.go
  52. 94
      vendor/xorm.io/xorm/caches/leveldb.go
  53. 20
      vendor/xorm.io/xorm/caches/lru.go
  54. 56
      vendor/xorm.io/xorm/caches/manager.go
  55. 6
      vendor/xorm.io/xorm/caches/memory_store.go
  56. 2
      vendor/xorm.io/xorm/contexts/context_cache.go
  57. 125
      vendor/xorm.io/xorm/convert.go
  58. 4
      vendor/xorm.io/xorm/convert/conversion.go
  59. 69
      vendor/xorm.io/xorm/core/db.go
  60. 0
      vendor/xorm.io/xorm/core/error.go
  61. 0
      vendor/xorm.io/xorm/core/rows.go
  62. 0
      vendor/xorm.io/xorm/core/scan.go
  63. 68
      vendor/xorm.io/xorm/core/stmt.go
  64. 91
      vendor/xorm.io/xorm/core/tx.go
  65. 278
      vendor/xorm.io/xorm/dialects/dialect.go
  66. 63
      vendor/xorm.io/xorm/dialects/driver.go
  67. 43
      vendor/xorm.io/xorm/dialects/filter.go
  68. 0
      vendor/xorm.io/xorm/dialects/gen_reserved.sh
  69. 197
      vendor/xorm.io/xorm/dialects/mssql.go
  70. 234
      vendor/xorm.io/xorm/dialects/mysql.go
  71. 227
      vendor/xorm.io/xorm/dialects/oracle.go
  72. 0
      vendor/xorm.io/xorm/dialects/pg_reserved.txt
  73. 338
      vendor/xorm.io/xorm/dialects/postgres.go
  74. 15
      vendor/xorm.io/xorm/dialects/quote.go
  75. 218
      vendor/xorm.io/xorm/dialects/sqlite3.go
  76. 90
      vendor/xorm.io/xorm/dialects/table_name.go
  77. 49
      vendor/xorm.io/xorm/dialects/time.go
  78. 2
      vendor/xorm.io/xorm/doc.go
  79. 820
      vendor/xorm.io/xorm/engine.go
  80. 232
      vendor/xorm.io/xorm/engine_cond.go
  81. 28
      vendor/xorm.io/xorm/engine_context.go
  82. 42
      vendor/xorm.io/xorm/engine_group.go
  83. 113
      vendor/xorm.io/xorm/engine_table.go
  84. 27
      vendor/xorm.io/xorm/error.go
  85. 5
      vendor/xorm.io/xorm/go.mod
  86. 19
      vendor/xorm.io/xorm/go.sum
  87. 332
      vendor/xorm.io/xorm/helpers.go
  88. 21
      vendor/xorm.io/xorm/helpler_time.go
  89. 41
      vendor/xorm.io/xorm/interface.go
  90. 2
      vendor/xorm.io/xorm/internal/json/json.go
  91. 79
      vendor/xorm.io/xorm/internal/statements/cache.go
  92. 66
      vendor/xorm.io/xorm/internal/statements/column_map.go
  93. 37
      vendor/xorm.io/xorm/internal/statements/expr_param.go
  94. 143
      vendor/xorm.io/xorm/internal/statements/insert.go
  95. 79
      vendor/xorm.io/xorm/internal/statements/pk.go
  96. 441
      vendor/xorm.io/xorm/internal/statements/query.go
  97. 996
      vendor/xorm.io/xorm/internal/statements/statement.go
  98. 38
      vendor/xorm.io/xorm/internal/statements/statement_args.go
  99. 295
      vendor/xorm.io/xorm/internal/statements/update.go
  100. 154
      vendor/xorm.io/xorm/internal/statements/values.go

5
go.mod

@ -116,7 +116,6 @@ require (
gopkg.in/testfixtures.v2 v2.5.0
mvdan.cc/xurls/v2 v2.1.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.6
xorm.io/core v0.7.3
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a
xorm.io/builder v0.3.7
xorm.io/xorm v1.0.0
)

10
go.sum

@ -39,6 +39,8 @@ gitea.com/macaron/session v0.0.0-20191207215012-613cebf0674d h1:XLww3CvnFZkXVwau
gitea.com/macaron/session v0.0.0-20191207215012-613cebf0674d/go.mod h1:FanKy3WjWb5iw/iZBPk4ggoQT9FcM6bkBPvmDmsH6tY=
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7 h1:N9QFoeNsUXLhl14mefLzGluqV7w2mGU3u+iZU+jCeWk=
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7/go.mod h1:kgsbFPPS4P+acDYDOPDa3N4IWWOuDJt5/INKRUz7aks=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@ -793,11 +795,11 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8=
xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU=
xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI=
xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
xorm.io/core v0.7.3 h1:W8ws1PlrnkS1CZU1YWaYLMQcQilwAmQXU0BJDJon+H0=
xorm.io/core v0.7.3/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
xorm.io/xorm v0.8.0 h1:iALxgJrX8O00f8Jk22GbZwPmxJNgssV5Mv4uc2HL9PM=
xorm.io/xorm v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a h1:hzGd080rlkZ5a7v6Tr3x8PJJnWPfKxGMMl92c8DNcww=
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
xorm.io/xorm v1.0.0 h1:ceiwUTrJHqfNFxIUcWjkcbz6kt7sINf2dOXlgLLhaQM=
xorm.io/xorm v1.0.0/go.mod h1:o4vnEsQ5V2F1/WK6w4XTwmiWJeGj82tqjAnHe44wVHY=

7
models/access.go

@ -207,7 +207,12 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAcces
// Delete old accesses and insert new ones for repository.
if _, err = e.Delete(&Access{RepoID: repo.ID}); err != nil {
return fmt.Errorf("delete old accesses: %v", err)
} else if _, err = e.Insert(newAccesses); err != nil {
}
if len(newAccesses) == 0 {
return nil
}
if _, err = e.Insert(newAccesses); err != nil {
return fmt.Errorf("insert new accesses: %v", err)
}
return nil

3
models/list_options.go

@ -25,6 +25,9 @@ func (opts ListOptions) getPaginatedSession() *xorm.Session {
func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
opts.setDefaultValues()
if opts.PageSize <= 0 {
return sess
}
return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
}

18
models/log.go

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/log"
"xorm.io/core"
xormlog "xorm.io/xorm/log"
)
// XORMLogBridge a logger bridge from Logger to xorm
@ -19,7 +19,7 @@ type XORMLogBridge struct {
}
// NewXORMLogger inits a log bridge for xorm
func NewXORMLogger(showSQL bool) core.ILogger {
func NewXORMLogger(showSQL bool) xormlog.Logger {
return &XORMLogBridge{
showSQL: showSQL,
logger: log.GetLogger("xorm"),
@ -72,22 +72,22 @@ func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
}
// Level get logger level
func (l *XORMLogBridge) Level() core.LogLevel {
func (l *XORMLogBridge) Level() xormlog.LogLevel {
switch l.logger.GetLevel() {
case log.TRACE, log.DEBUG:
return core.LOG_DEBUG
return xormlog.LOG_DEBUG
case log.INFO:
return core.LOG_INFO
return xormlog.LOG_INFO
case log.WARN:
return core.LOG_WARNING
return xormlog.LOG_WARNING
case log.ERROR, log.CRITICAL:
return core.LOG_ERR
return xormlog.LOG_ERR
}
return core.LOG_OFF
return xormlog.LOG_OFF
}
// SetLevel set the logger level
func (l *XORMLogBridge) SetLevel(lvl core.LogLevel) {
func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel) {
}
// ShowSQL set if record SQL

20
models/login_source.go

@ -22,8 +22,8 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"github.com/unknwon/com"
"xorm.io/core"
"xorm.io/xorm"
"xorm.io/xorm/convert"
)
// LoginType represents an login type.
@ -60,11 +60,11 @@ var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
// Ensure structs implemented interface.
var (
_ core.Conversion = &LDAPConfig{}
_ core.Conversion = &SMTPConfig{}
_ core.Conversion = &PAMConfig{}
_ core.Conversion = &OAuth2Config{}
_ core.Conversion = &SSPIConfig{}
_ convert.Conversion = &LDAPConfig{}
_ convert.Conversion = &SMTPConfig{}
_ convert.Conversion = &PAMConfig{}
_ convert.Conversion = &OAuth2Config{}
_ convert.Conversion = &SSPIConfig{}
)
// LDAPConfig holds configuration for LDAP login source.
@ -165,10 +165,10 @@ func (cfg *SSPIConfig) ToDB() ([]byte, error) {
type LoginSource struct {
ID int64 `xorm:"pk autoincr"`
Type LoginType
Name string `xorm:"UNIQUE"`
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
Cfg core.Conversion `xorm:"TEXT"`
Name string `xorm:"UNIQUE"`
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
Cfg convert.Conversion `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

24
models/migrations/v110.go

@ -5,32 +5,26 @@
package migrations
import (
"xorm.io/core"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func changeReviewContentToText(x *xorm.Engine) error {
if x.Dialect().DBType() == core.MYSQL {
switch x.Dialect().URI().DBType {
case schemas.MYSQL:
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
return err
}
if x.Dialect().DBType() == core.ORACLE {
case schemas.ORACLE:
_, err := x.Exec("ALTER TABLE review MODIFY content TEXT")
return err
}
if x.Dialect().DBType() == core.MSSQL {
case schemas.MSSQL:
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TEXT")
return err
}
if x.Dialect().DBType() == core.POSTGRES {
case schemas.POSTGRES:
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TYPE TEXT")
return err
default:
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
return nil
}
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
return nil
}

9
models/migrations/v81.go

@ -8,17 +8,18 @@ import (
"fmt"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func changeU2FCounterType(x *xorm.Engine) error {
var err error
switch x.Dialect().DriverName() {
case "mysql":
switch x.Dialect().URI().DBType {
case schemas.MYSQL:
_, err = x.Exec("ALTER TABLE `u2f_registration` MODIFY `counter` BIGINT")
case "postgres":
case schemas.POSTGRES:
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` SET DATA TYPE bigint")
case "mssql":
case schemas.MSSQL:
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` BIGINT")
}

28
models/models.go

@ -15,8 +15,9 @@ import (
// Needed for the MySQL driver
_ "github.com/go-sql-driver/mysql"
"xorm.io/core"
"xorm.io/xorm"
"xorm.io/xorm/names"
"xorm.io/xorm/schemas"
// Needed for the Postgresql driver
_ "github.com/lib/pq"
@ -127,7 +128,7 @@ func init() {
gonicNames := []string{"SSL", "UID"}
for _, name := range gonicNames {
core.LintGonicMapper[name] = true
names.LintGonicMapper[name] = true
}
}
@ -152,8 +153,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
return fmt.Errorf("Connect to database: %v", err)
}
x.ShowExecTime(true)
x.SetMapper(core.GonicMapper{})
x.SetMapper(names.GonicMapper{})
x.SetLogger(NewXORMLogger(!setting.ProdMode))
x.ShowSQL(!setting.ProdMode)
return x.StoreEngine("InnoDB").Sync2(tables...)
@ -166,8 +166,7 @@ func SetEngine() (err error) {
return fmt.Errorf("Failed to connect to database: %v", err)
}
x.ShowExecTime(true)
x.SetMapper(core.GonicMapper{})
x.SetMapper(names.GonicMapper{})
// WARNING: for serv command, MUST remove the output to os.stdout,
// so use log file to instead print to stdout.
x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
@ -249,21 +248,26 @@ func Ping() error {
// DumpDatabase dumps all data from database according the special database SQL syntax to file system.
func DumpDatabase(filePath string, dbType string) error {
var tbs []*core.Table
var tbs []*schemas.Table
for _, t := range tables {
t := x.TableInfo(t)
t.Table.Name = t.Name
tbs = append(tbs, t.Table)
t, err := x.TableInfo(t)
if err != nil {
return err
}
tbs = append(tbs, t)
}
if len(dbType) > 0 {
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))
return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType))
}
return x.DumpTablesToFile(tbs, filePath)
}
// MaxBatchInsertSize returns the table's max batch insert size
func MaxBatchInsertSize(bean interface{}) int {
t := x.TableInfo(bean)
t, err := x.TableInfo(bean)
if err != nil {
return 50
}
return 999 / len(t.ColumnsSeq())
}

12
models/org_team.go

@ -1072,12 +1072,14 @@ func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) {
return err
}
if _, err = sess.Insert(units); err != nil {
errRollback := sess.Rollback()
if errRollback != nil {
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
if len(units) > 0 {
if _, err = sess.Insert(units); err != nil {
errRollback := sess.Rollback()
if errRollback != nil {
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
}
return err
}
return err
}
return sess.Commit()

6
models/repo.go

@ -1417,8 +1417,10 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
return err
}
if _, err = sess.Insert(units); err != nil {
return err
if len(units) > 0 {
if _, err = sess.Insert(units); err != nil {
return err
}
}
return sess.Commit()

4
models/repo_unit.go

@ -10,8 +10,8 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"github.com/unknwon/com"
"xorm.io/core"
"xorm.io/xorm"
"xorm.io/xorm/convert"
)
// RepoUnit describes all units of a repository
@ -19,7 +19,7 @@ type RepoUnit struct {
ID int64
RepoID int64 `xorm:"INDEX(s)"`
Type UnitType `xorm:"INDEX(s)"`
Config core.Conversion `xorm:"TEXT"`
Config convert.Conversion `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
}

2
models/ssh_key.go

@ -524,7 +524,7 @@ func AddPublicKey(ownerID int64, name, content string, loginSourceID int64) (*Pu
func GetPublicKeyByID(keyID int64) (*PublicKey, error) {
key := new(PublicKey)
has, err := x.
Id(keyID).
ID(keyID).
Get(key)
if err != nil {
return nil, err

3
models/test_fixtures.go

@ -9,6 +9,7 @@ import (
"time"
"gopkg.in/testfixtures.v2"
"xorm.io/xorm/schemas"
)
var fixtures *testfixtures.Context
@ -36,7 +37,7 @@ func LoadFixtures() error {
fmt.Printf("LoadFixtures failed after retries: %v\n", err)
}
// Now if we're running postgres we need to tell it to update the sequences
if x.Dialect().DriverName() == "postgres" {
if x.Dialect().URI().DBType == schemas.POSTGRES {
results, err := x.QueryString(`SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||

4
models/unit_tests.go

@ -20,8 +20,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/unknwon/com"
"gopkg.in/testfixtures.v2"
"xorm.io/core"
"xorm.io/xorm"
"xorm.io/xorm/names"
)
// NonexistentID an ID that will never exist
@ -92,7 +92,7 @@ func CreateTestEngine(fixturesDir string) error {
if err != nil {
return err
}
x.SetMapper(core.GonicMapper{})
x.SetMapper(names.GonicMapper{})
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
return err
}

6
routers/admin/auths.go

@ -20,7 +20,7 @@ import (
"code.gitea.io/gitea/modules/util"
"github.com/unknwon/com"
"xorm.io/core"
"xorm.io/xorm/convert"
)
const (
@ -214,7 +214,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
ctx.Data["SSPIDefaultLanguage"] = ""
hasTLS := false
var config core.Conversion
var config convert.Conversion
switch models.LoginType(form.Type) {
case models.LoginLDAP, models.LoginDLDAP:
config = parseLDAPConfig(form)
@ -322,7 +322,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
return
}
var config core.Conversion
var config convert.Conversion
switch models.LoginType(form.Type) {
case models.LoginLDAP, models.LoginDLDAP:
config = parseLDAPConfig(form)

19
vendor/modules.txt

@ -766,12 +766,21 @@ mvdan.cc/xurls/v2
# strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
## explicit
strk.kbt.io/projects/go/libravatar
# xorm.io/builder v0.3.6
# xorm.io/builder v0.3.7
## explicit
xorm.io/builder
# xorm.io/core v0.7.3
## explicit
xorm.io/core
# xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a
# xorm.io/xorm v1.0.0
## explicit
xorm.io/xorm
xorm.io/xorm/caches
xorm.io/xorm/contexts
xorm.io/xorm/convert
xorm.io/xorm/core
xorm.io/xorm/dialects
xorm.io/xorm/internal/json
xorm.io/xorm/internal/statements
xorm.io/xorm/internal/utils
xorm.io/xorm/log
xorm.io/xorm/names
xorm.io/xorm/schemas
xorm.io/xorm/tags

71
vendor/xorm.io/builder/.drone.yml

@ -1,31 +1,6 @@
---
kind: pipeline
name: go1.10
workspace:
base: /go
path: src/xorm.io/builder
steps:
- name: test
pull: default
image: golang:1.10
commands:
- go get -u golang.org/x/lint/golint
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/go-xorm/sqlfiddle
- golint ./...
- go vet
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
when:
event:
- push
- tag
- pull_request
---
kind: pipeline
name: go1.11
name: testing
steps:
- name: test
@ -36,50 +11,6 @@ steps:
- golint ./...
- go vet
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
environment:
GOPROXY: https://goproxy.cn
GO111MODULE: "on"
when:
event:
- push
- tag
- pull_request
---
kind: pipeline
name: go1.12
steps:
- name: test
pull: default
image: golang:1.12
commands:
- go get -u golang.org/x/lint/golint
- golint ./...
- go vet
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
environment:
GOPROXY: https://goproxy.cn
GO111MODULE: "on"
when:
event:
- push
- tag
- pull_request
---
kind: pipeline
name: go1.13
steps:
- name: test
pull: default
image: golang:1.13
commands:
- go get -u golang.org/x/lint/golint
- golint ./...
- go vet
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
environment:
GOPROXY: https://goproxy.cn
GO111MODULE: "on"

1
vendor/xorm.io/builder/.gitignore

@ -0,0 +1 @@
.idea

60
vendor/xorm.io/builder/builder.go

@ -17,7 +17,7 @@ const (
insertType // insert
updateType // update
deleteType // delete
unionType // union
setOpType // set operation
)
// all databasees
@ -27,6 +27,10 @@ const (
MYSQL = "mysql"
MSSQL = "mssql"
ORACLE = "oracle"
UNION = "union"
INTERSECT = "intersect"
EXCEPT = "except"
)
type join struct {
@ -35,9 +39,10 @@ type join struct {
joinCond Cond
}
type union struct {
unionType string
builder *Builder
type setOp struct {
opType string
distinctType string
builder *Builder
}
type limit struct {
@ -56,7 +61,7 @@ type Builder struct {
cond Cond
selects []string
joins []join
unions []union
setOps []setOp
limitation *limit
insertCols []string
insertVals []interface{}
@ -144,33 +149,48 @@ func (b *Builder) Into(tableName string) *Builder {
}
// Union sets union conditions
func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder {
func (b *Builder) Union(distinctType string, cond *Builder) *Builder {
return b.setOperation(UNION, distinctType, cond)
}
// Intersect sets intersect conditions
func (b *Builder) Intersect(distinctType string, cond *Builder) *Builder {
return b.setOperation(INTERSECT, distinctType, cond)
}
// Except sets except conditions
func (b *Builder) Except(distinctType string, cond *Builder) *Builder {
return b.setOperation(EXCEPT, distinctType, cond)
}
func (b *Builder) setOperation(opType, distinctType string, cond *Builder) *Builder {
var builder *Builder
if b.optype != unionType {
if b.optype != setOpType {
builder = &Builder{cond: NewCond()}
builder.optype = unionType
builder.optype = setOpType
builder.dialect = b.dialect
builder.selects = b.selects
currentUnions := b.unions
// erase sub unions (actually append to new Builder.unions)
b.unions = nil
currentSetOps := b.setOps
// erase sub setOps (actually append to new Builder.unions)
b.setOps = nil
for e := range currentUnions {
currentUnions[e].builder.dialect = b.dialect
for e := range currentSetOps {
currentSetOps[e].builder.dialect = b.dialect
}
builder.unions = append(append(builder.unions, union{"", b}), currentUnions...)
builder.setOps = append(append(builder.setOps, setOp{opType, "", b}), currentSetOps...)
} else {
builder = b
}
if unionCond != nil {
if unionCond.dialect == "" && builder.dialect != "" {
unionCond.dialect = builder.dialect
if cond != nil {
if cond.dialect == "" && builder.dialect != "" {
cond.dialect = builder.dialect
}
builder.unions = append(builder.unions, union{unionTp, unionCond})
builder.setOps = append(builder.setOps, setOp{opType, distinctType, cond})
}
return builder
@ -240,8 +260,8 @@ func (b *Builder) WriteTo(w Writer) error {
return b.updateWriteTo(w)
case deleteType:
return b.deleteWriteTo(w)
case unionType:
return b.unionWriteTo(w)
case setOpType:
return b.setOpWriteTo(w)
}
return ErrNotSupportType

2
vendor/xorm.io/builder/builder_insert.go

@ -58,6 +58,8 @@ func (b *Builder) insertWriteTo(w Writer) error {
if e, ok := value.(expr); ok {
fmt.Fprintf(valBuffer, "(%s)", e.sql)
args = append(args, e.args...)
} else if value == nil {
fmt.Fprintf(valBuffer, `null`)
} else {
fmt.Fprint(valBuffer, "?")
args = append(args, value)

9
vendor/xorm.io/builder/builder_limit.go

@ -21,6 +21,9 @@ func (b *Builder) limitWriteTo(w Writer) error {
}
// erase limit condition
b.limitation = nil
defer func() {
b.limitation = limit
}()
ow := w.(*BytesWriter)
switch strings.ToLower(strings.TrimSpace(b.dialect)) {
@ -34,7 +37,7 @@ func (b *Builder) limitWriteTo(w Writer) error {
b.selects = append(selects, "ROWNUM RN")
var wb *Builder
if b.optype == unionType {
if b.optype == setOpType {
wb = Dialect(b.dialect).Select("at.*", "ROWNUM RN").
From(b, "at")
} else {
@ -55,7 +58,7 @@ func (b *Builder) limitWriteTo(w Writer) error {
return final.WriteTo(ow)
case SQLITE, MYSQL, POSTGRES:
// if type UNION, we need to write previous content back to current writer
if b.optype == unionType {
if b.optype == setOpType {
if err := b.WriteTo(ow); err != nil {
return err
}
@ -77,7 +80,7 @@ func (b *Builder) limitWriteTo(w Writer) error {
b.selects[1:]...), "ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS RN")
var wb *Builder
if b.optype == unionType {
if b.optype == setOpType {
wb = Dialect(b.dialect).Select("*", "ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS RN").
From(b, "at")
} else {

2
vendor/xorm.io/builder/builder_select.go

@ -63,7 +63,7 @@ func (b *Builder) selectWriteTo(w Writer) error {
}
switch b.subQuery.optype {
case selectType, unionType:
case selectType, setOpType:
fmt.Fprint(w, " FROM (")
if err := b.subQuery.WriteTo(w); err != nil {
return err

14
vendor/xorm.io/builder/builder_union.go → vendor/xorm.io/builder/builder_set_operations.go

@ -9,19 +9,19 @@ import (
"strings"
)
func (b *Builder) unionWriteTo(w Writer) error {
func (b *Builder) setOpWriteTo(w Writer) error {
if b.limitation != nil || b.cond.IsValid() ||
b.orderBy != "" || b.having != "" || b.groupBy != "" {
return ErrNotUnexpectedUnionConditions
}
for idx, u := range b.unions {
current := u.builder
for idx, o := range b.setOps {
current := o.builder
if current.optype != selectType {
return ErrUnsupportedUnionMembers
}
if len(b.unions) == 1 {
if len(b.setOps) == 1 {
if err := current.selectWriteTo(w); err != nil {
return err
}
@ -31,7 +31,11 @@ func (b *Builder) unionWriteTo(w Writer) error {
}
if idx != 0 {
fmt.Fprint(w, fmt.Sprintf(" UNION %v ", strings.ToUpper(u.unionType)))
if o.distinctType == "" {
fmt.Fprint(w, fmt.Sprintf(" %s ", strings.ToUpper(o.opType)))
} else {
fmt.Fprint(w, fmt.Sprintf(" %s %s ", strings.ToUpper(o.opType), strings.ToUpper(o.distinctType)))
}
}
fmt.Fprint(w, "(")

4
vendor/xorm.io/builder/builder_update.go

@ -45,6 +45,10 @@ func (b *Builder) updateWriteTo(w Writer) error {
}
}
if !b.cond.IsValid() {
return nil
}
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
return err
}

4
vendor/xorm.io/builder/cond_eq.go

@ -64,6 +64,10 @@ func (eq Eq) OpWriteTo(op string, w Writer) error {
return err
}
w.Append(int(v.(Decr)))
case nil:
if _, err := fmt.Fprintf(w, "%s=null", k); err != nil {
return err
}
default:
if _, err := fmt.Fprintf(w, "%s=?", k); err != nil {
return err

2
vendor/xorm.io/builder/go.mod

@ -3,6 +3,6 @@ module xorm.io/builder
go 1.11
require (
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a
github.com/stretchr/testify v1.3.0
)

4
vendor/xorm.io/builder/go.sum

@ -1,7 +1,7 @@
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y=
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

9
vendor/xorm.io/builder/sql.go

@ -75,6 +75,7 @@ func noSQLQuoteNeeded(a interface{}) bool {
}
t := reflect.TypeOf(a)
switch t.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return true
@ -133,12 +134,16 @@ func ConvertToBoundSQL(sql string, args []interface{}) (string, error) {
return buf.String(), nil
}
// ConvertPlaceholder replaces ? to $1, $2 ... or :1, :2 ... according prefix
// ConvertPlaceholder replaces the place holder ? to $1, $2 ... or :1, :2 ... according prefix
func ConvertPlaceholder(sql, prefix string) (string, error) {
buf := strings.Builder{}
var i, j, start int
var ready = true
for ; i < len(sql); i++ {
if sql[i] == '?' {
if sql[i] == '\'' && i > 0 && sql[i-1] != '\\' {
ready = !ready
}
if ready && sql[i] == '?' {
if _, err := buf.WriteString(sql[start:i]); err != nil {
return "", err
}

33
vendor/xorm.io/core/.drone.yml

@ -1,33 +0,0 @@
---
kind: pipeline
name: go1.12
steps:
- name: test
pull: default
image: golang:1.12
commands:
- go vet
- "go test -v -race -coverprofile=coverage.txt -covermode=atomic -dbConn=\"root:@tcp(mysql:3306)/core_test?charset=utf8mb4\""
environment:
GO111MODULE: "on"
GOPROXY: https://goproxy.cn
when:
event:
- push
- tag
- pull_request
services:
- name: mysql
pull: default
image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: core_test
when:
event:
- push
- tag
- pull_request

1
vendor/xorm.io/core/.gitignore

@ -1 +0,0 @@
*.db

27
vendor/xorm.io/core/LICENSE

@ -1,27 +0,0 @@
Copyright (c) 2013 - 2015 Lunny Xiao <xiaolunwen@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

118
vendor/xorm.io/core/README.md

@ -1,118 +0,0 @@
Core is a lightweight wrapper of sql.DB.
[![Build Status](https://drone.gitea.com/api/badges/xorm/core/status.svg)](https://drone.gitea.com/xorm/core)
[![Test Coverage](https://gocover.io/_badge/xorm.io/core)](https://gocover.io/xorm.io/core)
[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/gitea)](https://goreportcard.com/report/xorm.io/core)
# Open
```Go
db, _ := core.Open(db, connstr)
```
# SetMapper
```Go
db.SetMapper(SameMapper())
```
## Scan usage
### Scan
```Go
rows, _ := db.Query()
for rows.Next() {
rows.Scan()
}
```
### ScanMap
```Go
rows, _ := db.Query()
for rows.Next() {
rows.ScanMap()
```
### ScanSlice
You can use `[]string`, `[][]byte`, `[]interface{}`, `[]*string`, `[]sql.NullString` to ScanSclice. Notice, slice's length should be equal or less than select columns.
```Go
rows, _ := db.Query()
cols, _ := rows.Columns()
for rows.Next() {
var s = make([]string, len(cols))
rows.ScanSlice(&s)
}
```
```Go
rows, _ := db.Query()
cols, _ := rows.Columns()
for rows.Next() {
var s = make([]*string, len(cols))
rows.ScanSlice(&s)
}
```
### ScanStruct
```Go
rows, _ := db.Query()
for rows.Next() {
rows.ScanStructByName()
rows.ScanStructByIndex()
}
```
## Query usage
```Go
rows, err := db.Query("select * from table where name = ?", name)
user = User{
Name:"lunny",
}
rows, err := db.QueryStruct("select * from table where name = ?Name",
&user)
var user = map[string]interface{}{
"name": "lunny",
}
rows, err = db.QueryMap("select * from table where name = ?name",
&user)
```
## QueryRow usage
```Go
row := db.QueryRow("select * from table where name = ?", name)
user = User{
Name:"lunny",
}
row := db.QueryRowStruct("select * from table where name = ?Name",
&user)
var user = map[string]interface{}{
"name": "lunny",
}
row = db.QueryRowMap("select * from table where name = ?name",
&user)
```
## Exec usage
```Go
db.Exec("insert into user (`name`, title, age, alias, nick_name,created) values (?,?,?,?,?,?)", name, title, age, alias...)
user = User{
Name:"lunny",
Title:"test",
Age: 18,
}
result, err = db.ExecStruct("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)",
&user)
var user = map[string]interface{}{
"Name": "lunny",
"Title": "test",
"Age": 18,
}
result, err = db.ExecMap("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)",
&user)
```

1
vendor/xorm.io/core/benchmark.sh

@ -1 +0,0 @@
go test -v -bench=. -run=XXX

327
vendor/xorm.io/core/dialect.go

@ -1,327 +0,0 @@
// Copyright 2019 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package core
import (
"fmt"
"strings"
"time"
)
type DbType string
type Uri struct {
DbType DbType
Proto string
Host string
Port string
DbName string
User string
Passwd string
Charset string
Laddr string
Raddr string
Timeout time.Duration
Schema string
}
// a dialect is a driver's wrapper
type Dialect interface {
SetLogger(logger ILogger)
Init(*DB, *Uri, string, string) error
URI() *Uri
DB() *DB
DBType() DbType
SqlType(*Column) string
FormatBytes(b []byte) string
DriverName() string
DataSourceName() string
IsReserved(string) bool
Quote(string) string
AndStr() string
OrStr() string
EqStr() string
RollBackStr() string
AutoIncrStr() string
SupportInsertMany() bool
SupportEngine() bool
SupportCharset() bool
SupportDropIfExists() bool
IndexOnTable() bool
ShowCreateNull() bool
IndexCheckSql(tableName, idxName string) (string, []interface{})
TableCheckSql(tableName string) (string, []interface{})
IsColumnExist(tableName string, colName string) (bool, error)
CreateTableSql(table *Table, tableName, storeEngine, charset string) string
DropTableSql(tableName string) string
CreateIndexSql(tableName string, index *Index) string
DropIndexSql(tableName string, index *Index) string
ModifyColumnSql(tableName string, col *Column) string
ForUpdateSql(query string) string
// CreateTableIfNotExists(table *Table, tableName, storeEngine, charset string) error
// MustDropTable(tableName string) error
GetColumns(tableName string) ([]string, map[string]*Column, error)
GetTables() ([]*Table, error)
GetIndexes(tableName string) (map[string]*Index, error)
Filters() []Filter
SetParams(params map[string]string)
}
func OpenDialect(dialect Dialect) (*DB, error) {
return Open(dialect.DriverName(), dialect.DataSourceName())
}
// Base represents a basic dialect and all real dialects could embed this struct
type Base struct {
db *DB
dialect Dialect
driverName string
dataSourceName string
logger ILogger
*Uri
}
func (b *Base) DB() *DB {
return b.db
}
func (b *Base) SetLogger(logger ILogger) {
b.logger = logger
}
func (b *Base) Init(db *DB, dialect Dialect, uri *Uri, drivername, dataSourceName string) error {
b.db, b.dialect, b.Uri = db, dialect, uri
b.driverName, b.dataSourceName = drivername, dataSourceName
return nil
}
func (b *Base) URI() *Uri {
return b.Uri
}
func (b *Base) DBType() DbType {
return b.Uri.DbType
}
func (b *Base) FormatBytes(bs []byte) string {
return fmt.Sprintf("0x%x", bs)
}
func (b *Base) DriverName() string {
return b.driverName
}
func (b *Base) ShowCreateNull() bool {
return true
}
func (b *Base) DataSourceName() string {
return b.dataSourceName
}
func (b *Base) AndStr() string {
return "AND"
}
func (b *Base) OrStr() string {
return "OR"
}
func (b *Base) EqStr() string {
return "="
}
func (db *Base) RollBackStr() string {
return "ROLL BACK"
}
func (db *Base) SupportDropIfExists() bool {
return true
}
func (db *Base) DropTableSql(tableName string) string {
quote := db.dialect.Quote
return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName))
}
func (db *Base) HasRecords(query string, args ...interface{}) (bool, error) {
db.LogSQL(query, args)
rows, err := db.DB().Query(query, args...)
if err != nil {
return false, err
}
defer rows.Close()
if rows.Next() {
return true, nil
}
return false, nil
}
func (db *Base) IsColumnExist(tableName, colName string) (bool, error) {
query := fmt.Sprintf(
"SELECT %v FROM %v.%v WHERE %v = ? AND %v = ? AND %v = ?",
db.dialect.Quote("COLUMN_NAME"),
db.dialect.Quote("INFORMATION_SCHEMA"),
db.dialect.Quote("COLUMNS"),
db.dialect.Quote("TABLE_SCHEMA"),
db.dialect.Quote("TABLE_NAME"),
db.dialect.Quote("COLUMN_NAME"),
)
return db.HasRecords(query, db.DbName, tableName, colName)
}
/*
func (db *Base) CreateTableIfNotExists(table *Table, tableName, storeEngine, charset string) error {
sql, args := db.dialect.TableCheckSql(tableName)
rows, err := db.DB().Query(sql, args...)
if db.Logger != nil {
db.Logger.Info("[sql]", sql, args)
}
if err != nil {
return err
}
defer rows.Close()
if rows.Next() {
return nil
}
sql = db.dialect.CreateTableSql(table, tableName, storeEngine, charset)
_, err = db.DB().Exec(sql)
if db.Logger != nil {
db.Logger.Info("[sql]", sql)
}
return err
}*/
func (db *Base) CreateIndexSql(tableName string, index *Index) string {
quote := db.dialect.Quote
var unique string
var idxName string
if index.Type == UniqueType {
unique = " UNIQUE"
}
idxName = index.XName(tableName)
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
quote(idxName), quote(tableName),
quote(strings.Join(index.Cols, quote(","))))
}
func (db *Base) DropIndexSql(tableName string, index *Index) string {
quote := db.dialect.Quote
var name string
if index.IsRegular {
name = index.XName(tableName)
} else {
name = index.Name
}
return fmt.Sprintf("DROP INDEX %v ON %s", quote(name), quote(tableName))
}
func (db *Base) ModifyColumnSql(tableName string, col *Column) string {
return fmt.Sprintf("alter table %s MODIFY COLUMN %s", tableName, col.StringNoPk(db.dialect))
}
func (b *Base) CreateTableSql(table *Table, tableName, storeEngine, charset string) string {
var sql string
sql = "CREATE TABLE IF NOT EXISTS "
if tableName == "" {
tableName = table.Name
}
sql += b.dialect.Quote(tableName)
sql += " ("
if len(table.ColumnsSeq()) > 0 {
pkList := table.PrimaryKeys
for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName)
if col.IsPrimaryKey && len(pkList) == 1 {
sql += col.String(b.dialect)
} else {
sql += col.StringNoPk(b.dialect)
}
sql = strings.TrimSpace(sql)
if b.DriverName() == MYSQL && len(col.Comment) > 0 {
sql += " COMMENT '" + col.Comment + "'"
}
sql += ", "
}
if len(pkList) > 1 {
sql += "PRIMARY KEY ( "
sql += b.dialect.Quote(strings.Join(pkList, b.dialect.Quote(",")))
sql += " ), "
}
sql = sql[:len(sql)-2]
}
sql += ")"
if b.dialect.SupportEngine() && storeEngine != "" {
sql += " ENGINE=" + storeEngine
}
if b.dialect.SupportCharset() {
if len(charset) == 0 {
charset = b.dialect.URI().Charset
}
if len(charset) > 0 {
sql += " DEFAULT CHARSET " + charset
}
}
return sql
}
func (b *Base) ForUpdateSql(query string) string {
return query + " FOR UPDATE"
}
func (b *Base) LogSQL(sql string, args []interface{}) {
if b.logger != nil && b.logger.IsShowSQL() {
if len(args) > 0 {
b.logger.Infof("[SQL] %v %v", sql, args)
} else {
b.logger.Infof("[SQL] %v", sql)
}
}
}
func (b *Base) SetParams(params map[string]string) {
}
var (
dialects = map[string]func() Dialect{}
)
// RegisterDialect register database dialect
func RegisterDialect(dbName DbType, dialectFunc func() Dialect) {
if dialectFunc == nil {
panic("core: Register dialect is nil")
}
dialects[strings.ToLower(string(dbName))] = dialectFunc // !nashtsai! allow override dialect
}
// QueryDialect query if registered database dialect
func QueryDialect(dbName DbType) Dialect {
if d, ok := dialects[strings.ToLower(string(dbName))]; ok {
return d()
}
return nil
}

31
vendor/xorm.io/core/driver.go

@ -1,31 +0,0 @@
// Copyright 2019 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package core
type Driver interface {
Parse(string, string) (*Uri, error)
}
var (
drivers = map[string]Driver{}
)
func RegisterDriver(driverName string, driver Driver) {
if driver == nil {
panic("core: Register driver is nil")
}
if _, dup := drivers[driverName]; dup {
panic("core: Register called twice for driver " + driverName)
}
drivers[driverName] = driver
}
func QueryDriver(driverName string) Driver {
return drivers[driverName]
}
func RegisteredDriverSize() int {
return len(drivers)
}

93