From 41a2e64812326d7ca348b36830cd3882bda671ba Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 25 Apr 2024 16:32:34 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/crud/crud_table_update_func_test.go_ | 8 ++--- .../pkg/db/crud/crud_table_update_test.go_ | 8 ++--- internal/create_files/create_files.go | 29 +++++++++++-------- .../create_files/crud_tables/crud_tables.go | 6 ++++ .../grpc_client_tables/grpc_client_tables.go | 23 ++++++--------- 5 files changed, 40 insertions(+), 34 deletions(-) diff --git a/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ b/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ index 2eccf51..c630c15 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ @@ -6,9 +6,9 @@ func TestUpdate(t *testing.T) { //прочитаем из БД crud := Crud_DB{} - Model := lawsuit_status_types.LawsuitStatusType{} - Model.ID = Postgres_ID_Test - err := crud.Read(&Model) + m := lawsuit_status_types.LawsuitStatusType{} + m.ID = Postgres_ID_Test + err := crud.Read(&m) if err != nil { t.Error("TestUpdate() Read() error: ", err) } @@ -16,7 +16,7 @@ func TestUpdate(t *testing.T) { //запишем в БД это же значение Otvet := lawsuit_status_types.LawsuitStatusType{} Otvet.ID = Postgres_ID_Test - Otvet.ColumnName = Model.ColumnName + Otvet.ColumnName = m.ColumnName err = crud.Update(&Otvet) if err != nil { t.Error("TestUpdate() Update() error: ", err) diff --git a/bin/templates/pkg/db/crud/crud_table_update_test.go_ b/bin/templates/pkg/db/crud/crud_table_update_test.go_ index ec57f84..386bc00 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_test.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_test.go_ @@ -16,15 +16,15 @@ func TestUpdateManyFields(t *testing.T) { //прочитаем из БД crud := Crud_DB{} - Model := lawsuit_status_types.LawsuitStatusType{} - Model.ID = Postgres_ID_Test - err := crud.Read(&Model) + m := lawsuit_status_types.LawsuitStatusType{} + m.ID = Postgres_ID_Test + err := crud.Read(&m) if err != nil { t.Error("TestUpdateManyFields() Read() error: ", err) } //запишем в БД это же значение - err = crud.UpdateManyFields(&Model, nil) + err = crud.UpdateManyFields(&m, nil) if err != nil { t.Error("TestUpdateManyFields() UpdateManyFields() error: ", err) } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index f6c5ab7..40166f5 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -218,6 +218,9 @@ func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string { Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+".IsZero() == false") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName) } + Otvet = strings.ReplaceAll(Otvet, "Otvet.ID = ", OtvetColumnName+" = ") + Otvet = strings.ReplaceAll(Otvet, "Otvet.ID != ", OtvetColumnName+" != ") + Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " "+OtvetColumnName+")") return Otvet } @@ -253,6 +256,10 @@ func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string { Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+".IsZero() == false") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName) } + Otvet = strings.ReplaceAll(Otvet, "m.ID = ", OtvetColumnName+" = ") + Otvet = strings.ReplaceAll(Otvet, " = m.ID", " = "+OtvetColumnName) + Otvet = strings.ReplaceAll(Otvet, ", m.ID,", ", "+OtvetColumnName+",") + Otvet = strings.ReplaceAll(Otvet, "(m.ID)", "("+OtvetColumnName+")") return Otvet } @@ -1312,9 +1319,9 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, //найдём тип колонки PrimaryKey PrimaryKey_Column := FindPrimaryKeyColumn(Table1) - PrimaryKey_TypeGo := PrimaryKey_Column.TypeGo + //PrimaryKey_TypeGo := PrimaryKey_Column.TypeGo //Text_Request_ID := "Request_ID" - Otvet, _ = FindTextProtobufRequest(Table1, PrimaryKey_TypeGo) + Otvet, _ = FindTextProtobufRequest(Table1, TypeGo) //Text_Request_ID = "Request_" + TextID //найдём строку по типу колонки @@ -1682,7 +1689,7 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string { Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) } } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, TextFind+IDMinimum) + Otvet = strings.ReplaceAll(Otvet, TextFind, "const Postgres_ID_Test = "+IDMinimum) } return Otvet @@ -1712,15 +1719,14 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string { } // ReplaceTextRequestID - заменяет RequestId{} на RequestString{} -func ReplaceTextRequestID(Text string, Table1 *types.Table) string { +func ReplaceTextRequestID(Text string, Table1 *types.Table, Column1 *types.Column) string { Otvet := Text - PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) - TypeGo := PrimaryKeyColumn.TypeGo + TypeGo := Column1.TypeGo - TextRequestID, TextID := FindTextProtobufRequest(Table1, TypeGo) + TextRequestID, _ := FindTextProtobufRequest(Table1, TypeGo) Otvet = strings.ReplaceAll(Otvet, "RequestId{}", TextRequestID+"{}") - Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID) + //Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID) return Otvet } @@ -1747,17 +1753,16 @@ func ReplaceTextRequestID_PrimaryKey1(Text string, Table1 *types.Table, TextRequ TextRequestID, TextID := FindTextProtobufRequestPrimaryKey(Table1, TypeGo) - TextConvertID, GolangCode := FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.") + _, GolangCode := FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.") if GolangCode != "" { Otvet = strings.ReplaceAll(Otvet, "ID := "+TextRequest+".ID", GolangCode) Otvet = strings.ReplaceAll(Otvet, TextRequest+".ID = ", TextRequest+"."+TextID+" = ") - } else { - Otvet = strings.ReplaceAll(Otvet, TextRequest+".ID", TextConvertID) } Otvet = strings.ReplaceAll(Otvet, "RequestId{}", TextRequestID+"{}") Otvet = strings.ReplaceAll(Otvet, "*grpc_proto.RequestId", "*grpc_proto."+TextRequestID) //Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID) + Otvet = strings.ReplaceAll(Otvet, TextRequest+".ID", TextRequest+"."+TextID) return Otvet } @@ -1770,7 +1775,7 @@ func ReplaceIDtoID(Text string, Table1 *types.Table) string { OtvetColumnName := FindTextConvertGolangTypeToProtobufType(Table1, PrimaryKeyColumn, "") Otvet = strings.ReplaceAll(Otvet, "int64(ID)", OtvetColumnName) - Otvet = strings.ReplaceAll(Otvet, "(ID int64", "(ID "+PrimaryKeyColumn.TypeGo) + Otvet = strings.ReplaceAll(Otvet, "(ID int64", "("+PrimaryKeyColumn.NameGo+" "+PrimaryKeyColumn.TypeGo) return Otvet } diff --git a/internal/create_files/crud_tables/crud_tables.go b/internal/create_files/crud_tables/crud_tables.go index 589a683..efb73c0 100644 --- a/internal/create_files/crud_tables/crud_tables.go +++ b/internal/create_files/crud_tables/crud_tables.go @@ -704,6 +704,8 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCrud = create_files.AddImport(TextCrud, ModelTableURL) + TextCrud = create_files.ReplacePrimaryKeyM_ID(TextCrud, Table1) + TextCrud = create_files.ReplacePrimaryKeyOtvetID(TextCrud, Table1) //TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) } @@ -771,6 +773,9 @@ func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Tab TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1, Column1.TypeGo) DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo) + Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) + Otvet = create_files.ReplacePrimaryKeyOtvetID(Otvet, Table1) + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest) @@ -825,6 +830,7 @@ func CreateFilesCache(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCache = create_files.AddImport(TextCache, ModelTableURL) + TextCache = create_files.ReplacePrimaryKeyOtvetID(TextCache, Table1) //TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1) } diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index ee05559..eff52b2 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -219,12 +219,12 @@ func CreateFilesTest(Table1 *types.Table) error { //Postgres_ID_Test = ID Minimum TextGRPCClient = create_files.Replace_Postgres_ID_Test(TextGRPCClient, Table1) - //замена ID на PrimaryKey - TextGRPCClient = create_files.ReplacePrimaryKeyOtvetID(TextGRPCClient, Table1) - //замена Otvet.ID = -1 TextGRPCClient = create_files.ReplaceOtvetIDEqual1(TextGRPCClient, Table1) + //замена ID на PrimaryKey + TextGRPCClient = create_files.ReplacePrimaryKeyOtvetID(TextGRPCClient, Table1) + //добавим импорт uuid TextGRPCClient = create_files.CheckAndAddImportUUID_FromText(TextGRPCClient) @@ -242,12 +242,6 @@ func CreateFilesTest(Table1 *types.Table) error { } TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1) - //Postgres_ID_Test = ID Minimum - if Table1.IDMinimum != "" { - TextFind := "const Postgres_ID_Test = " - TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"0", TextFind+Table1.IDMinimum) - } - // замена ID на PrimaryKey TextGRPCClient = create_files.ReplacePrimaryKeyOtvetID(TextGRPCClient, Table1) @@ -525,10 +519,8 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types. TextRequest, TextRequestFieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.") //замена RequestId{} - Otvet = create_files.ReplaceTextRequestID(Otvet, Table1) - - // - Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) + Otvet = create_files.ReplaceTextRequestID(Otvet, Table1, Column1) + Otvet = create_files.ReplaceTextRequestID_PrimaryKey(Otvet, Table1) //замена ID на PrimaryKey Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) @@ -615,6 +607,9 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { TextGRPC_Client = create_files.ReplacePrimaryKeyOtvetID(TextGRPC_Client, Table1) + //замена m.ID = Postgres_ID_Test + TextGRPC_Client = create_files.ReplacePrimaryKeyM_ID(TextGRPC_Client, Table1) + } //создание текста @@ -684,7 +679,7 @@ func FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc string, Table1 *typ func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string { Otvet := TextGRPC_ClientUpdateFunc - Otvet = create_files.ReplaceTextRequestID(Otvet, Table1) + Otvet = create_files.ReplaceTextRequestID(Otvet, Table1, Column1) Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) Otvet = create_files.ReplacePrimaryKeyOtvetID(Otvet, Table1)