From e8c7884efe9a7cd3f1c43742d580a6a38c76ff90 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 15 Feb 2024 15:59:34 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20CreateFi?= =?UTF-8?q?lesUpdateEveryColumn()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server_grpc_table_update_func_test.go_ | 19 ++++++++++++------- internal/create_files/create_files.go | 18 ++++++++++++++++++ .../grpc_server_tables/grpc_server_tables.go | 19 ++++++++++++++----- internal/postgres/postgres.go | 3 ++- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ index 1d39a64..58efcd6 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ @@ -9,20 +9,25 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) { Request := grpc_proto.RequestId{} Request.ID = LawsuitStatusType_ID_Test Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() - Model, err := server1.LawsuitStatusType_Read(ctx, &Request) + Response1, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Update() Read() error: ", err) } - if Otvet.ModelString == "" { + if Response1.ModelString == "" { t.Error("Test_server_LawsuitStatusType_Update() Read() error: ModelString=''") } + Model := lawsuit_status_types.LawsuitStatusType{} + err = Model.GetModelFromJSON(Response1.ModelString) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Update_ColumnName() GetModelFromJSON() error: ", err) + } //запишем в БД это же значение - Request := grpc_proto.RequestString{} - Request.ID = LawsuitStatusType_ID_Test - Request.ColumnName = Model.ColumnName - Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() - _, err := server1.LawsuitStatusType_Update(ctx, &Request) + Request2 := grpc_proto.RequestString{} + Request2.ID = LawsuitStatusType_ID_Test + Request2.ColumnName = Model.ColumnName + Request2.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() + _, err = server1.LawsuitStatusType_Update(ctx, &Request2) if err != nil { t.Error("Test_server_LawsuitStatusType_Update() Update() error: ", err) } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index fe32d8e..893fde7 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -486,6 +486,24 @@ func FindTextDefaultValue(Type_go string) string { return Otvet } +// FindTextDefaultValueSQL - возвращает значение по умолчанию для типа +func FindTextDefaultValueSQL(Type_go string) string { + var Otvet string + + switch Type_go { + case "string": + Otvet = `''` + case "int", "int32", "int64", "float32", "float64", "uint", "uint32", "uint64": + Otvet = "0" + case "time.Time": + Otvet = "null" + case "bool": + Otvet = "false" + } + + return Otvet +} + // FindURL_Alias - возвращает URL репозитория с пакетом "alias" func FindURL_Alias() string { Otvet := "" diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index c425f58..3a12a94 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -494,6 +494,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { TextGRPCServer := "package " + PackageName + "\n\n" TextGRPCServer = TextGRPCServer + `import ( "context" + "testing" "github.com/ManyakRus/starter/config_main" ) @@ -513,7 +514,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { CrudStarterURL := create_files.FindCrudStarterURL() TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) - TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + //TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) //} //создание текста @@ -529,6 +530,12 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer + //Import Timestamp + TextGRPCServer = create_files.CheckAndAddImportTimestamp_FromText(TextGRPCServer) + + //SkipNow() если нет строк в БД + TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1) + //удаление пустого импорта TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer) TextGRPCServer = create_files.DeleteEmptyLines(TextGRPCServer) @@ -575,14 +582,16 @@ func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *typ ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Model.") + TextRequest2, TextRequestField, TextRequestFieldGolang := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request2.") + TextModelColumnName := create_files.FindTextConvertGolangTypeToProtobufType(Table1, Column1, "Model.") + Otvet = strings.ReplaceAll(Otvet, "Request2.ColumnName", "Request2."+TextRequestField) + Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestString", "grpc_proto."+TextRequest2) Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update(", ModelName+"_"+FuncName+"(") Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestString", "grpc_proto."+TextRequest) - Otvet = strings.ReplaceAll(Otvet, "Model.ColumnName", TextRequestFieldName) - Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Request.ColumnName", TextRequestFieldGolang) + Otvet = strings.ReplaceAll(Otvet, "Model.ColumnName", TextModelColumnName) Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) return Otvet diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index 374219c..b1888bf 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -285,7 +285,8 @@ func FillIDMinimum(MapTable map[string]*types.Table) { if NameID == "" { continue } - TextSQL := "SELECT Min(" + NameID + ") from \"" + postgres_gorm.Settings.DB_SCHEMA + "\".\"" + TableName + "\"" + DefaultValueSQL := create_files.FindTextDefaultValueSQL(TypeGo) + TextSQL := "SELECT Min(" + NameID + ") from \"" + postgres_gorm.Settings.DB_SCHEMA + "\".\"" + TableName + "\" WHERE " + NameID + " <> " + DefaultValueSQL ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*60) defer ctxCancelFunc() db.WithContext(ctx)