Skip to content

Commit

Permalink
fix: fi remove sort tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Jul 16, 2023
1 parent d509d3a commit a3de779
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
8 changes: 2 additions & 6 deletions driver/mysql/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ func (c *Column) IntoOrmTag(indexes []*Index, keyNameCount map[string]int) strin
b.WriteString("uniqueIndex:")
b.WriteString(v.KeyName)
} else {
if v.KeyName == "sort" { // 兼容 gorm 本身 sort 标签
b.WriteString("index")
} else {
b.WriteString("index:")
b.WriteString(v.KeyName)
}
b.WriteString("index:")
b.WriteString(v.KeyName)
if v.IndexType == "FULLTEXT" {
b.WriteString(",class:FULLTEXT")
}
Expand Down
1 change: 0 additions & 1 deletion internal/sts/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func Parse(v any) error {
fmt.Println(fv.Name)
fmt.Println(fvt.Kind())
fmt.Printf("%#v\n", field.Build(nil))

}

return nil
Expand Down
8 changes: 2 additions & 6 deletions schema/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ func (c *Column) IntoOrmTag() string {
b.WriteString("uniqueIndex:")
b.WriteString(v.KeyName)
} else {
if v.KeyName == "sort" { // 兼容 gorm 本身 sort 标签
b.WriteString("index")
} else {
b.WriteString("index:")
b.WriteString(v.KeyName)
}
b.WriteString("index:")
b.WriteString(v.KeyName)
if v.IndexType == "FULLTEXT" {
b.WriteString(",class:FULLTEXT")
}
Expand Down
28 changes: 28 additions & 0 deletions schema/index.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package schema

import (
"fmt"
"strings"
)

type Index struct {
Table string
KeyName string
Expand All @@ -10,3 +15,26 @@ type Index struct {
IndexType string
Columns []string
}

func (self *Index) IntoMysqlString() string {
b := strings.Builder{}
b.Grow(32)
if !self.Unique {
b.WriteString("KEY")
} else {
if self.PrimaryKey {
b.WriteString("PRIMARY KEY")
} else {
b.WriteString("UNIQUE KEY")
}
}
if !self.PrimaryKey {
b.WriteString(" ")
b.WriteString(fmt.Sprintf("`%s`", self.KeyName))
}
b.WriteString(" (`")
b.WriteString(strings.Join(self.Columns, "`, `"))
b.WriteString("`) USING ")
b.WriteString(self.IndexType)
return b.String()
}

0 comments on commit a3de779

Please sign in to comment.