upgrade xorm to v1.0.6 (#14246)
This commit is contained in:
parent
8db0372a45
commit
126c9331d6
2
go.mod
2
go.mod
|
@ -122,7 +122,7 @@ require (
|
|||
mvdan.cc/xurls/v2 v2.2.0
|
||||
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
|
||||
xorm.io/builder v0.3.7
|
||||
xorm.io/xorm v1.0.5
|
||||
xorm.io/xorm v1.0.6
|
||||
)
|
||||
|
||||
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.4
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1612,5 +1612,5 @@ 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/xorm v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
|
||||
xorm.io/xorm v1.0.5 h1:LRr5PfOUb4ODPR63YwbowkNDwcolT2LnkwP/TUaMaB0=
|
||||
xorm.io/xorm v1.0.5/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
||||
xorm.io/xorm v1.0.6 h1:7eco1c8QUpGz+3dztpLDj9gU1bTiQdFC/KtmPaLxUJk=
|
||||
xorm.io/xorm v1.0.6/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -982,7 +982,7 @@ strk.kbt.io/projects/go/libravatar
|
|||
# xorm.io/builder v0.3.7
|
||||
## explicit
|
||||
xorm.io/builder
|
||||
# xorm.io/xorm v1.0.5
|
||||
# xorm.io/xorm v1.0.6
|
||||
## explicit
|
||||
xorm.io/xorm
|
||||
xorm.io/xorm/caches
|
||||
|
|
14
vendor/xorm.io/xorm/CHANGELOG.md
generated
vendored
14
vendor/xorm.io/xorm/CHANGELOG.md
generated
vendored
|
@ -3,6 +3,20 @@
|
|||
This changelog goes through all the changes that have been made in each release
|
||||
without substantial changes to our git log.
|
||||
|
||||
## [1.0.6](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1308) - 2021-01-05
|
||||
|
||||
* BUGFIXES
|
||||
* Fix bug when modify column on mssql (#1849)
|
||||
* Fix find and count bug with cols (#1826)
|
||||
* Fix update bug (#1823)
|
||||
* Fix json tag with other type (#1822)
|
||||
* ENHANCEMENTS
|
||||
* prevent panic when struct with unexport field (#1839)
|
||||
* Automatically convert datetime to int64 (#1715)
|
||||
* MISC
|
||||
* Fix index (#1841)
|
||||
* Performance improvement for columnsbyName (#1788)
|
||||
|
||||
## [1.0.5](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1299) - 2020-09-08
|
||||
|
||||
* BUGFIXES
|
||||
|
|
2
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
2
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
|
@ -163,7 +163,7 @@ func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
|
|||
|
||||
func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false)
|
||||
return fmt.Sprintf("alter table %s MODIFY COLUMN %s", tableName, s)
|
||||
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", tableName, s)
|
||||
}
|
||||
|
||||
func (b *Base) ForUpdateSQL(query string) string {
|
||||
|
|
5
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
5
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
|
@ -368,6 +368,11 @@ func (db *mssql) DropTableSQL(tableName string) (string, bool) {
|
|||
"DROP TABLE \"%s\"", tableName, tableName), true
|
||||
}
|
||||
|
||||
func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false)
|
||||
return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s", tableName, s)
|
||||
}
|
||||
|
||||
func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{idxName}
|
||||
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
|
||||
|
|
2
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
2
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
|
@ -483,7 +483,7 @@ func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableNa
|
|||
continue
|
||||
}
|
||||
|
||||
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []'\"")
|
||||
indexName := strings.Trim(strings.TrimSpace(sql[nNStart+6:nNEnd]), "`[]'\"")
|
||||
var isRegular bool
|
||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||
index.Name = indexName[5+len(tableName):]
|
||||
|
|
21
vendor/xorm.io/xorm/engine.go
generated
vendored
21
vendor/xorm.io/xorm/engine.go
generated
vendored
|
@ -61,6 +61,10 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return newEngine(driverName, dataSourceName, dialect, db)
|
||||
}
|
||||
|
||||
func newEngine(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) {
|
||||
cacherMgr := caches.NewManager()
|
||||
mapper := names.NewCacheMapper(new(names.SnakeMapper))
|
||||
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr)
|
||||
|
@ -88,7 +92,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
|||
engine.SetLogger(log.NewLoggerAdapter(logger))
|
||||
|
||||
runtime.SetFinalizer(engine, func(engine *Engine) {
|
||||
engine.Close()
|
||||
_ = engine.Close()
|
||||
})
|
||||
|
||||
return engine, nil
|
||||
|
@ -101,6 +105,14 @@ func NewEngineWithParams(driverName string, dataSourceName string, params map[st
|
|||
return engine, err
|
||||
}
|
||||
|
||||
// NewEngineWithDialectAndDB new a db manager according to the parameter.
|
||||
// If you do not want to use your own dialect or db, please use NewEngine.
|
||||
// For creating dialect, you can call dialects.OpenDialect. And, for creating db,
|
||||
// you can call core.Open or core.FromDB.
|
||||
func NewEngineWithDialectAndDB(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) {
|
||||
return newEngine(driverName, dataSourceName, dialect, db)
|
||||
}
|
||||
|
||||
// EnableSessionID if enable session id
|
||||
func (engine *Engine) EnableSessionID(enable bool) {
|
||||
engine.logSessionID = enable
|
||||
|
@ -347,13 +359,16 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error {
|
|||
var seq int
|
||||
for _, index := range indexes {
|
||||
for _, name := range index.Cols {
|
||||
parts := strings.Split(name, " ")
|
||||
parts := strings.Split(strings.TrimSpace(name), " ")
|
||||
if len(parts) > 1 {
|
||||
if parts[1] == "DESC" {
|
||||
seq = 1
|
||||
} else if parts[1] == "ASC" {
|
||||
seq = 0
|
||||
}
|
||||
}
|
||||
if col := table.GetColumn(parts[0]); col != nil {
|
||||
var colName = strings.Trim(parts[0], `"`)
|
||||
if col := table.GetColumn(colName); col != nil {
|
||||
col.Indexes[index.Name] = index.Type
|
||||
} else {
|
||||
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq())
|
||||
|
|
4
vendor/xorm.io/xorm/internal/statements/statement.go
generated
vendored
4
vendor/xorm.io/xorm/internal/statements/statement.go
generated
vendored
|
@ -704,7 +704,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
|||
col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) {
|
||||
continue
|
||||
}
|
||||
if col.SQLType.IsJson() {
|
||||
if col.IsJSON {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -813,7 +813,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
if col.SQLType.IsJson() {
|
||||
if col.IsJSON {
|
||||
if col.SQLType.IsText() {
|
||||
bytes, err := json.DefaultJSONHandler.Marshal(fieldValue.Interface())
|
||||
if err != nil {
|
||||
|
|
2
vendor/xorm.io/xorm/internal/statements/update.go
generated
vendored
2
vendor/xorm.io/xorm/internal/statements/update.go
generated
vendored
|
@ -204,7 +204,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
if !col.SQLType.IsJson() {
|
||||
if !col.IsJSON {
|
||||
table, err := statement.tagParser.ParseWithCache(fieldValue)
|
||||
if err != nil {
|
||||
val = fieldValue.Interface()
|
||||
|
|
2
vendor/xorm.io/xorm/internal/statements/values.go
generated
vendored
2
vendor/xorm.io/xorm/internal/statements/values.go
generated
vendored
|
@ -86,7 +86,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
|
|||
return t.Float64, nil
|
||||
}
|
||||
|
||||
if !col.SQLType.IsJson() {
|
||||
if !col.IsJSON {
|
||||
// !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString
|
||||
if v, ok := fieldValue.Interface().(driver.Valuer); ok {
|
||||
return v.Value()
|
||||
|
|
1
vendor/xorm.io/xorm/schemas/column.go
generated
vendored
1
vendor/xorm.io/xorm/schemas/column.go
generated
vendored
|
@ -51,6 +51,7 @@ type Column struct {
|
|||
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
|
||||
return &Column{
|
||||
Name: name,
|
||||
IsJSON: sqlType.IsJson(),
|
||||
TableName: "",
|
||||
FieldName: fieldName,
|
||||
SQLType: sqlType,
|
||||
|
|
7
vendor/xorm.io/xorm/schemas/table.go
generated
vendored
7
vendor/xorm.io/xorm/schemas/table.go
generated
vendored
|
@ -58,12 +58,7 @@ func (table *Table) ColumnsSeq() []string {
|
|||
}
|
||||
|
||||
func (table *Table) columnsByName(name string) []*Column {
|
||||
for k, cols := range table.columnsMap {
|
||||
if strings.EqualFold(k, name) {
|
||||
return cols
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return table.columnsMap[strings.ToLower(name)]
|
||||
}
|
||||
|
||||
// GetColumn returns column according column name, if column not found, return nil
|
||||
|
|
4
vendor/xorm.io/xorm/session.go
generated
vendored
4
vendor/xorm.io/xorm/session.go
generated
vendored
|
@ -503,7 +503,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
|
|||
fieldType := fieldValue.Type()
|
||||
hasAssigned := false
|
||||
|
||||
if col.SQLType.IsJson() {
|
||||
if col.IsJSON {
|
||||
var bs []byte
|
||||
if rawValueType.Kind() == reflect.String {
|
||||
bs = []byte(vv.String())
|
||||
|
@ -683,7 +683,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
|
|||
session.engine.logger.Errorf("sql.Sanner error: %v", err)
|
||||
hasAssigned = false
|
||||
}
|
||||
} else if col.SQLType.IsJson() {
|
||||
} else if col.IsJSON {
|
||||
if rawValueType.Kind() == reflect.String {
|
||||
hasAssigned = true
|
||||
x := reflect.New(fieldType)
|
||||
|
|
24
vendor/xorm.io/xorm/session_convert.go
generated
vendored
24
vendor/xorm.io/xorm/session_convert.go
generated
vendored
|
@ -168,7 +168,29 @@ func (session *Session) bytes2Value(col *schemas.Column, fieldValue *reflect.Val
|
|||
} else if strings.EqualFold(sdata, "false") {
|
||||
x = 0
|
||||
} else {
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
if col.SQLType.Name == schemas.DateTime {
|
||||
if len(sdata) == 20 {
|
||||
t, err := time.Parse("2006-01-02T15:04:05Z", sdata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
}
|
||||
x = t.Unix()
|
||||
} else if len(sdata) == 19 {
|
||||
var parseFormat = "2006-01-02 15:04:05"
|
||||
if sdata[10] == 'T' {
|
||||
parseFormat = "2006-01-02T15:04:05"
|
||||
}
|
||||
t, err := time.Parse(parseFormat, sdata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
}
|
||||
x = t.Unix()
|
||||
} else {
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
}
|
||||
} else {
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
|
|
3
vendor/xorm.io/xorm/session_find.go
generated
vendored
3
vendor/xorm.io/xorm/session_find.go
generated
vendored
|
@ -57,6 +57,9 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
|
|||
if session.statement.SelectStr != "" {
|
||||
session.statement.SelectStr = ""
|
||||
}
|
||||
if len(session.statement.ColumnMap) > 0 {
|
||||
session.statement.ColumnMap = []string{}
|
||||
}
|
||||
if session.statement.OrderStr != "" {
|
||||
session.statement.OrderStr = ""
|
||||
}
|
||||
|
|
9
vendor/xorm.io/xorm/session_update.go
generated
vendored
9
vendor/xorm.io/xorm/session_update.go
generated
vendored
|
@ -273,8 +273,15 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
k = ct.Elem().Kind()
|
||||
}
|
||||
if k == reflect.Struct {
|
||||
var refTable = session.statement.RefTable
|
||||
if refTable == nil {
|
||||
refTable, err = session.engine.TableInfo(condiBean[0])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
var err error
|
||||
autoCond, err = session.statement.BuildConds(session.statement.RefTable, condiBean[0], true, true, false, true, false)
|
||||
autoCond, err = session.statement.BuildConds(refTable, condiBean[0], true, true, false, true, false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
4
vendor/xorm.io/xorm/tags/parser.go
generated
vendored
4
vendor/xorm.io/xorm/tags/parser.go
generated
vendored
|
@ -253,7 +253,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
|
|||
addIndex(indexName, table, col, indexType)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if fieldValue.CanSet() {
|
||||
var sqlType schemas.SQLType
|
||||
if fieldValue.CanAddr() {
|
||||
if _, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
||||
|
@ -272,6 +272,8 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
|
|||
if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) {
|
||||
idFieldColName = col.Name
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
if col.IsAutoIncrement {
|
||||
col.Nullable = false
|
||||
|
|
3
vendor/xorm.io/xorm/tags/tag.go
generated
vendored
3
vendor/xorm.io/xorm/tags/tag.go
generated
vendored
|
@ -226,6 +226,9 @@ func CommentTagHandler(ctx *Context) error {
|
|||
// SQLTypeTagHandler describes SQL Type tag handler
|
||||
func SQLTypeTagHandler(ctx *Context) error {
|
||||
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagName}
|
||||
if strings.EqualFold(ctx.tagName, "JSON") {
|
||||
ctx.col.IsJSON = true
|
||||
}
|
||||
if len(ctx.params) > 0 {
|
||||
if ctx.tagName == schemas.Enum {
|
||||
ctx.col.EnumOptions = make(map[string]int)
|
||||
|
|
Loading…
Reference in a new issue