Add comment support on create table [mysql only currently] (#616)
* add comment support on create table * remove wrong file
This commit is contained in:
parent
233706969a
commit
f86679d536
9
tag.go
9
tag.go
|
@ -54,6 +54,7 @@ var (
|
|||
"UNIQUE": UniqueTagHandler,
|
||||
"CACHE": CacheTagHandler,
|
||||
"NOCACHE": NoCacheTagHandler,
|
||||
"COMMENT": CommentTagHandler,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -192,6 +193,14 @@ func UniqueTagHandler(ctx *tagContext) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CommentTagHandler add comment to column
|
||||
func CommentTagHandler(ctx *tagContext) error {
|
||||
if len(ctx.params) > 0 {
|
||||
ctx.col.Comment = strings.Trim(ctx.params[0], "' ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SQLTypeTagHandler describes SQL Type tag handler
|
||||
func SQLTypeTagHandler(ctx *tagContext) error {
|
||||
ctx.col.SQLType = core.SQLType{Name: ctx.tagName}
|
||||
|
|
37
tag_test.go
37
tag_test.go
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -234,4 +235,38 @@ func TestAutoIncrTag(t *testing.T) {
|
|||
assert.False(t, cols[0].IsAutoIncrement)
|
||||
assert.True(t, cols[0].IsPrimaryKey)
|
||||
assert.Equal(t, "id", cols[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTagComment(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
// FIXME: only support mysql
|
||||
if testEngine.dialect.DriverName() != core.MYSQL {
|
||||
return
|
||||
}
|
||||
|
||||
type TestComment1 struct {
|
||||
Id int64 `xorm:"comment(主键)"`
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync2(new(TestComment1)))
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
assert.EqualValues(t, 1, len(tables[0].Columns()))
|
||||
assert.EqualValues(t, "主键", tables[0].Columns()[0].Comment)
|
||||
|
||||
assert.NoError(t, testEngine.DropTables(new(TestComment1)))
|
||||
|
||||
type TestComment2 struct {
|
||||
Id int64 `xorm:"comment('主键')"`
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync2(new(TestComment2)))
|
||||
|
||||
tables, err = testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
assert.EqualValues(t, 1, len(tables[0].Columns()))
|
||||
assert.EqualValues(t, "主键", tables[0].Columns()[0].Comment)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue