From bba3caded448dad2e03bad6864da961b65d0b12f Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 21 Aug 2024 15:17:40 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20find=5Fb?= =?UTF-8?q?y=5Ffunctions.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/create_files/create_files.go | 75 ++++++++++++------- .../grpc_client_tables/grpc_client_tables.go | 2 +- .../grpc_client_tables_findby.go | 3 +- .../server_grpc_tables/server_grpc_tables.go | 2 +- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index a79b6a9..1bec47d 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -396,9 +396,9 @@ func ReplacePrimaryKeyOtvetID_ManyPK1(Text string, Table1 *types.Table, Variable } else { TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n" } - TextM := ConvertGolangVariableToProtobufVariable(Column1, "m") + TextM := ConvertGolangVariableToProtobufVariable(Table1, Column1, "m") TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n" - TextInt64ID := ConvertGolangVariableToProtobufVariable(Column1, "") + TextInt64ID := ConvertGolangVariableToProtobufVariable(Table1, Column1, "") TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n" TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n" @@ -1927,7 +1927,7 @@ func DeleteCommentFromString(TextFrom string) string { } // ConvertGolangVariableToProtobufVariable - возвращает имя переменной + имя колонки, преобразованное в тип protobuf -func ConvertGolangVariableToProtobufVariable(Column1 *types.Column, VariableName string) string { +func ConvertGolangVariableToProtobufVariable(Table1 *types.Table, Column1 *types.Column, VariableName string) string { Otvet := "" if Column1 == nil { @@ -1940,24 +1940,49 @@ func ConvertGolangVariableToProtobufVariable(Column1 *types.Column, VariableName } Otvet = VariableName + Dot + Column1.NameGo + //найдём alias + _, HasAlias := types.MapConvertID[Table1.Name+"."+Column1.Name] + //преобразуем alias в обычный тип, и дату в timestamp - switch Column1.TypeGo { - case "time.Time": - Otvet = "timestamppb.New(" + VariableName + Dot + Column1.NameGo + ")" - case "string": - Otvet = "string(" + VariableName + Dot + Column1.NameGo + ")" - case "int64": - Otvet = "int64(" + VariableName + Dot + Column1.NameGo + ")" - case "int32": - Otvet = "int32(" + VariableName + Dot + Column1.NameGo + ")" - case "bool": - Otvet = "bool(" + VariableName + Dot + Column1.NameGo + ")" - case "float32": - Otvet = "float32(" + VariableName + Dot + Column1.NameGo + ")" - case "float64": - Otvet = "float64(" + VariableName + Dot + Column1.NameGo + ")" - case "uuid.UUID": - Otvet = VariableName + Dot + Column1.NameGo + ".String()" + if HasAlias == true { + switch Column1.TypeGo { + case "time.Time": + Otvet = "timestamppb.New(" + VariableName + Dot + Column1.NameGo + ")" + case "string": + Otvet = "string(" + VariableName + Dot + Column1.NameGo + ")" + case "int64": + Otvet = "int64(" + VariableName + Dot + Column1.NameGo + ")" + case "int32": + Otvet = "int32(" + VariableName + Dot + Column1.NameGo + ")" + case "bool": + Otvet = "bool(" + VariableName + Dot + Column1.NameGo + ")" + case "float32": + Otvet = "float32(" + VariableName + Dot + Column1.NameGo + ")" + case "float64": + Otvet = "float64(" + VariableName + Dot + Column1.NameGo + ")" + case "uuid.UUID": + Otvet = VariableName + Dot + Column1.NameGo + ".String()" + } + + } else { + switch Column1.TypeGo { + case "time.Time": + Otvet = "timestamppb.New(" + VariableName + Dot + Column1.NameGo + ")" + case "string": + Otvet = VariableName + Dot + Column1.NameGo + case "int64": + Otvet = VariableName + Dot + Column1.NameGo + case "int32": + Otvet = VariableName + Dot + Column1.NameGo + case "bool": + Otvet = VariableName + Dot + Column1.NameGo + case "float32": + Otvet = VariableName + Dot + Column1.NameGo + case "float64": + Otvet = VariableName + Dot + Column1.NameGo + case "uuid.UUID": + Otvet = VariableName + Dot + Column1.NameGo + ".String()" + } } return Otvet @@ -2379,7 +2404,7 @@ func Replace_Model_ID_Test_ManyPK(Text string, Table1 *types.Table) string { for _, Column1 := range MassPK { Name := strings.ToUpper(Column1.NameGo) VariableName := Table1.NameGo + "_" + Name + "_Test" - Text1 := ConvertGolangVariableToProtobufVariable(Column1, VariableName) + Text1 := ConvertGolangVariableToProtobufVariable(Table1, Column1, VariableName) RequestColumnName := FindRequestFieldName(Table1, Column1) TextNew = TextNew + "\tRequest." + RequestColumnName + " = " + Text1 + "\n" } @@ -2391,7 +2416,7 @@ func Replace_Model_ID_Test_ManyPK(Text string, Table1 *types.Table) string { for _, Column1 := range MassPK { Name := strings.ToUpper(Column1.NameGo) VariableName := Table1.NameGo + "_" + Name + "_Test" - Text1 := ConvertGolangVariableToProtobufVariable(Column1, VariableName) + Text1 := ConvertGolangVariableToProtobufVariable(Table1, Column1, VariableName) RequestColumnName := FindRequestFieldName(Table1, Column1) TextNew = TextNew + "\tRequest2." + RequestColumnName + " = " + Text1 + "\n" } @@ -2531,7 +2556,7 @@ func ReplaceIDtoID1(Text string, Table1 *types.Table) string { Otvet := Text PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) - OtvetColumnName := ConvertGolangVariableToProtobufVariable(PrimaryKeyColumn, "") + OtvetColumnName := ConvertGolangVariableToProtobufVariable(Table1, PrimaryKeyColumn, "") if OtvetColumnName == "" { return Otvet } @@ -2582,7 +2607,7 @@ func FindTextID_VariableName_Many(Table1 *types.Table, VariableName string) (Tex Comma := "" MassPrimaryKey := FindPrimaryKeyColumns(Table1) for _, PrimaryKey1 := range MassPrimaryKey { - OtvetColumnName := ConvertGolangVariableToProtobufVariable(PrimaryKey1, "") + OtvetColumnName := ConvertGolangVariableToProtobufVariable(Table1, PrimaryKey1, "") if OtvetColumnName == "" { continue } @@ -2900,7 +2925,7 @@ func FindRequestFieldName_FromMass(Column *types.Column, MassColumns []*types.Co } Suffix := "_" + strconv.Itoa(Number) - Otvet = ConvertGolangTypeNameToProtobufFieldName(Column.Type) + Otvet = ConvertGolangTypeNameToProtobufFieldName(Column.TypeGo) if Number > 1 { Otvet = Otvet + Suffix } 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 352ea27..2777da8 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -555,7 +555,7 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types. Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) // - ColumnNameGolang := create_files.ConvertGolangVariableToProtobufVariable(Column1, "m") + ColumnNameGolang := create_files.ConvertGolangVariableToProtobufVariable(Table1, Column1, "m") _, IDTypeGo := create_files.FindPrimaryKeyNameTypeGo(Table1) diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables_findby.go b/internal/create_files/grpc_client_tables/grpc_client_tables_findby.go index 82fd139..67e4e0d 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables_findby.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables_findby.go @@ -153,7 +153,8 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false") } TextRequest := create_files.FindRequestFieldName_FromMass(Column1, MassColumns) - TextAssign = TextAssign + "\tRequest." + TextRequest + " = m." + Column1.NameGo + "\n" + ValueM := create_files.ConvertGolangVariableToProtobufVariable(Table1, Column1, "m") + TextAssign = TextAssign + "\tRequest." + TextRequest + " = " + ValueM + "\n" FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo diff --git a/internal/create_files/server_grpc_tables/server_grpc_tables.go b/internal/create_files/server_grpc_tables/server_grpc_tables.go index 60610e5..3b39ba2 100644 --- a/internal/create_files/server_grpc_tables/server_grpc_tables.go +++ b/internal/create_files/server_grpc_tables/server_grpc_tables.go @@ -743,7 +743,7 @@ func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *typ ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName _, TextRequestField, TextRequestFieldGolang, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request2.") - TextModelColumnName := create_files.ConvertGolangVariableToProtobufVariable(Column1, "m") + TextModelColumnName := create_files.ConvertGolangVariableToProtobufVariable(Table1, Column1, "m") TextRequestID := create_files.FindTextProtobufRequest_ManyPK(Table1) //Postgres_ID_Test = ID Minimum