Skip to content

Commit c870756

Browse files
authored
reafactor: modify modeName and tag name (#14)
* chore: modify License * refactor: modify modeName and tag name
1 parent ce8e51a commit c870756

13 files changed

+43
-43
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ if err != nil {
7777

7878
### 2、定义Model
7979

80-
使用tag("xfield")定义struct,tag指定数据库表中的column name。
80+
使用tag("column")定义struct,tag指定数据库表中的column name。
8181

8282
```
8383
type TestTable struct {
8484
//指定table name
8585
TestTable gobatis.ModelName "test_table"
8686
//指定表字段id
87-
Id int64 `xfield:"id"`
87+
Id int64 `column:"id"`
8888
//指定表字段username
89-
Username string `xfield:"username"`
89+
Username string `column:"username"`
9090
//指定表字段password
91-
Password string `xfield:"password"`
91+
Password string `column:"password"`
9292
}
9393
```
9494

common/define.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ package common
2525
type IterFunc func(idx int64, bean interface{}) bool
2626

2727
const (
28-
FieldName = "xfield"
28+
ColumnName = "column"
2929
)

init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ import (
2424
)
2525

2626
func init() {
27-
var typeModelName ModelName
27+
var typeModelName TableName
2828
reflection.SetModelNameType(reflect.TypeOf(typeModelName))
2929
}

objectmanager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/acmestack/gobatis/reflection"
2525
)
2626

27-
type ModelName string
27+
type TableName string
2828

2929
type ObjectCache struct {
3030
objCache map[string]reflection.Object

reflection/object.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ func GetReflectMapInfo(rt reflect.Type, rv reflect.Value) (Object, error) {
460460
// a)、如果含有tag,则使用tag作为tablename;
461461
// b)、如果不含有tag,则使用fieldName作为tablename。
462462
//2、如果结构体中不含有gobatis.ModelName类型的字段,则使用结构体名称作为tablename
463-
//3、如果结构体中含有xfield的tag,则:
463+
//3、如果结构体中含有column的tag,则:
464464
// a)、如果tag为‘-’,则不进行columne与field的映射;
465465
// b)、如果tag不为‘-’使用tag name作为column名称与field映射。
466-
//4、如果结构体中不含有xfield的tag,则使用field name作为column名称与field映射
466+
//4、如果结构体中不含有column的tag,则使用field name作为column名称与field映射
467467
//5、如果字段的tag为‘-’,则不进行columne与field的映射;
468468
func GetStructInfo(bean interface{}) (*StructInfo, error) {
469469
return GetReflectStructInfo(reflect.TypeOf(bean), reflect.ValueOf(bean))
@@ -515,7 +515,7 @@ func GetReflectStructInfo(rt reflect.Type, rv reflect.Value) (*StructInfo, error
515515
}
516516

517517
fieldName := rtf.Name
518-
tagName := rtf.Tag.Get(common.FieldName)
518+
tagName := rtf.Tag.Get(common.ColumnName)
519519
if tagName == "-" {
520520
continue
521521
} else if tagName != "" {

test/cmd/test_table.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
)
2424

2525
type TestTable struct {
26-
//TableName gobatis.ModelName `test_table`
27-
Id int `xfield:"id"`
28-
Username string `xfield:"username"`
29-
Password string `xfield:"password"`
30-
Createtime time.Time `xfield:"createtime"`
26+
//TableName gobatis.TableName `test_table`
27+
Id int `column:"id"`
28+
Username string `column:"username"`
29+
Password string `column:"password"`
30+
Createtime time.Time `column:"createtime"`
3131
}
3232

3333
func (m *TestTable) Select(sess *gobatis.Session) ([]TestTable, error) {

test/mysql/runner_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import (
3030
)
3131

3232
type TestTable struct {
33-
TestTable gobatis.ModelName "test_table"
34-
Id int64 `xfield:"id"`
35-
Username string `xfield:"username"`
36-
Password string `xfield:"password"`
33+
TestTable gobatis.TableName "test_table"
34+
Id int64 `column:"id"`
35+
Username string `column:"username"`
36+
Password string `column:"password"`
3737
}
3838

3939
func (t *TestTable) String() string {

test/postgresql/runner_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929
)
3030

3131
type TestTable struct {
32-
TestTable gobatis.ModelName "test_table"
33-
Id int64 `xfield:"id"`
34-
Username string `xfield:"username"`
35-
Password string `xfield:"password"`
32+
TestTable gobatis.TableName "test_table"
33+
Id int64 `column:"id"`
34+
Username string `column:"username"`
35+
Password string `column:"password"`
3636
}
3737

3838
func (t *TestTable) String() string {

test/reflection_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
)
2828

2929
type TestStruct1 struct {
30-
TestTable gobatis.ModelName "test_table"
31-
Username string `xfield:"username"`
32-
Password string `xfield:"password"`
30+
TestTable gobatis.TableName "test_table"
31+
Username string `column:"username"`
32+
Password string `column:"password"`
3333
}
3434

3535
func TestReflection1(t *testing.T) {
@@ -39,8 +39,8 @@ func TestReflection1(t *testing.T) {
3939
}
4040

4141
type TestStruct2 struct {
42-
TestTable gobatis.ModelName
43-
Username string `xfield:"-"`
42+
TestTable gobatis.TableName
43+
Username string `column:"-"`
4444
Password string `-`
4545
}
4646

@@ -134,7 +134,7 @@ func TestReflectionParseMap(t *testing.T) {
134134
}
135135

136136
type testParseStruct struct {
137-
Name gobatis.ModelName `parse_struct`
137+
Name gobatis.TableName `parse_struct`
138138
Username string
139139
Password string
140140
}

test/runner_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
)
2727

2828
type TestTable struct {
29-
TestTable gobatis.ModelName "test_table"
30-
Id int64 `xfield:"id"`
31-
Username string `xfield:"username"`
32-
Password string `xfield:"password"`
29+
TestTable gobatis.TableName "test_table"
30+
Id int64 `column:"id"`
31+
Username string `column:"username"`
32+
Password string `column:"password"`
3333
}
3434

3535
func connect() factory.Factory {

test/sql_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
)
2626

2727
type SqlTest struct {
28-
Id int64 `xfield:"id"`
29-
Username string `xfield:"username"`
30-
Password string `xfield:"password"`
28+
Id int64 `column:"id"`
29+
Username string `column:"username"`
30+
Password string `column:"password"`
3131
}
3232

3333
var sessionMgr *gobatis.SessionManager

test/sqlite/runner_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929
)
3030

3131
type TestTable struct {
32-
TestTable gobatis.ModelName "test_table"
33-
Id int64 `xfield:"id"`
34-
Username string `xfield:"username"`
35-
Password string `xfield:"password"`
32+
TestTable gobatis.TableName "test_table"
33+
Id int64 `column:"id"`
34+
Username string `column:"username"`
35+
Password string `column:"password"`
3636
}
3737

3838
func (t *TestTable) String() string {

test/sqlparse_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ func TestSqlParserWithParamMap3(t *testing.T) {
178178
}
179179

180180
type TestSqlParserStruct struct {
181-
TestTable gobatis.ModelName "test_table"
182-
Id int `xfield:"id"`
183-
Name string `xfield:"name"`
181+
TestTable gobatis.TableName "test_table"
182+
Id int `column:"id"`
183+
Name string `column:"name"`
184184
}
185185

186186
func TestSqlParserWithParamMap4(t *testing.T) {

0 commit comments

Comments
 (0)