dto -> do for package gdb

This commit is contained in:
John Guo 2022-01-17 21:10:58 +08:00
parent 220ed74ad1
commit 9345eb5e94
4 changed files with 21 additions and 21 deletions

View File

@ -56,7 +56,7 @@ const (
OrmTagForWith = "with"
OrmTagForWithWhere = "where"
OrmTagForWithOrder = "order"
OrmTagForDto = "dto"
OrmTagForDo = "do"
)
var (
@ -67,18 +67,18 @@ var (
structTagPriority = append([]string{OrmTagForStruct}, gconv.StructTagPriority...)
)
// isDtoStruct checks and returns whether given type is a DTO struct.
func isDtoStruct(object interface{}) bool {
// isDoStruct checks and returns whether given type is a DO struct.
func isDoStruct(object interface{}) bool {
// It checks by struct name like "XxxForDao", to be compatible with old version.
// TODO remove this compatible codes in future.
reflectType := reflect.TypeOf(object)
if gstr.HasSuffix(reflectType.String(), modelForDaoSuffix) {
return true
}
// It checks by struct meta for DTO struct in version.
// It checks by struct meta for DO struct in version.
if ormTag := gmeta.Get(object, OrmTagForStruct); !ormTag.IsEmpty() {
match, _ := gregex.MatchString(
fmt.Sprintf(`%s\s*:\s*([^,]+)`, OrmTagForDto),
fmt.Sprintf(`%s\s*:\s*([^,]+)`, OrmTagForDo),
ormTag.String(),
)
if len(match) > 1 {
@ -394,9 +394,9 @@ func formatWhereHolder(db DB, in formatWhereHolderInput) (newWhere string, newAr
}
case reflect.Struct:
// If the `where` parameter is DTO struct, it then adds `OmitNil` option for this condition,
// If the `where` parameter is DO struct, it then adds `OmitNil` option for this condition,
// which will filter all nil parameters in `where`.
if isDtoStruct(in.Where) {
if isDoStruct(in.Where) {
in.OmitNil = true
}
// If `where` struct implements `iIterator` interface,

View File

@ -73,10 +73,10 @@ func (m *Model) Data(data ...interface{}) *Model {
switch reflectInfo.OriginKind {
case reflect.Slice, reflect.Array:
if reflectInfo.OriginValue.Len() > 0 {
// If the `data` parameter is a DTO struct,
// If the `data` parameter is a DO struct,
// it then adds `OmitNilData` option for this condition,
// which will filter all nil parameters in `data`.
if isDtoStruct(reflectInfo.OriginValue.Index(0).Interface()) {
if isDoStruct(reflectInfo.OriginValue.Index(0).Interface()) {
model = model.OmitNilData()
model.option |= optionOmitNilDataInternal
}
@ -88,10 +88,10 @@ func (m *Model) Data(data ...interface{}) *Model {
model.data = list
case reflect.Struct:
// If the `data` parameter is a DTO struct,
// If the `data` parameter is a DO struct,
// it then adds `OmitNilData` option for this condition,
// which will filter all nil parameters in `data`.
if isDtoStruct(value) {
if isDoStruct(value) {
model = model.OmitNilData()
}
if v, ok := data[0].(iInterfaces); ok {

View File

@ -13,13 +13,13 @@ import (
"github.com/gogf/gf/v2/test/gtest"
)
func Test_Model_Insert_Data_DTO(t *testing.T) {
func Test_Model_Insert_Data_DO(t *testing.T) {
table := createTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"dto:true"`
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
@ -46,13 +46,13 @@ func Test_Model_Insert_Data_DTO(t *testing.T) {
})
}
func Test_Model_Insert_Data_LIst_DTO(t *testing.T) {
func Test_Model_Insert_Data_LIst_DO(t *testing.T) {
table := createTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"dto:true"`
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
@ -94,13 +94,13 @@ func Test_Model_Insert_Data_LIst_DTO(t *testing.T) {
})
}
func Test_Model_Update_Data_DTO(t *testing.T) {
func Test_Model_Update_Data_DO(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"dto:true"`
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
@ -124,13 +124,13 @@ func Test_Model_Update_Data_DTO(t *testing.T) {
})
}
func Test_Model_Where_DTO(t *testing.T) {
func Test_Model_Where_DO(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"dto:true"`
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}

View File

@ -465,7 +465,7 @@ CREATE TABLE %s (
})
}
func Test_SoftUpdateTime_WithDTO(t *testing.T) {
func Test_SoftUpdateTime_WithDO(t *testing.T) {
table := "time_test_table_" + gtime.TimestampNanoStr()
if _, err := db.Exec(ctx, fmt.Sprintf(`
CREATE TABLE %s (
@ -500,7 +500,7 @@ CREATE TABLE %s (
// Update.
time.Sleep(2 * time.Second)
type User struct {
g.Meta `orm:"dto:true"`
g.Meta `orm:"do:true"`
Id interface{}
Num interface{}
CreatedAt interface{}