From 9345eb5e946feee1b5750af9d6e51f2783731e8c Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 17 Jan 2022 21:10:58 +0800 Subject: [PATCH] dto -> do for package gdb --- database/gdb/gdb_func.go | 14 +++++++------- database/gdb/gdb_model_insert.go | 8 ++++---- ...t.go => gdb_z_mysql_feature_model_do_test.go} | 16 ++++++++-------- .../gdb_z_mysql_feature_time_maintain_test.go | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) rename database/gdb/{gdb_z_mysql_feature_model_dto_test.go => gdb_z_mysql_feature_model_do_test.go} (95%) diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index a29c49636..b9055028a 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -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, diff --git a/database/gdb/gdb_model_insert.go b/database/gdb/gdb_model_insert.go index cd17de0f0..e598d5eb4 100644 --- a/database/gdb/gdb_model_insert.go +++ b/database/gdb/gdb_model_insert.go @@ -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 { diff --git a/database/gdb/gdb_z_mysql_feature_model_dto_test.go b/database/gdb/gdb_z_mysql_feature_model_do_test.go similarity index 95% rename from database/gdb/gdb_z_mysql_feature_model_dto_test.go rename to database/gdb/gdb_z_mysql_feature_model_do_test.go index e722595fd..dae9c5da2 100644 --- a/database/gdb/gdb_z_mysql_feature_model_dto_test.go +++ b/database/gdb/gdb_z_mysql_feature_model_do_test.go @@ -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{} diff --git a/database/gdb/gdb_z_mysql_feature_time_maintain_test.go b/database/gdb/gdb_z_mysql_feature_time_maintain_test.go index 2d762c9b9..71bb3b3e0 100644 --- a/database/gdb/gdb_z_mysql_feature_time_maintain_test.go +++ b/database/gdb/gdb_z_mysql_feature_time_maintain_test.go @@ -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{}