1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-16 21:52:42 +02:00

сделал objects

This commit is contained in:
Nikitin Aleksandr 2024-11-06 14:38:57 +03:00
parent fde67f369b
commit 1b7659ed48
13 changed files with 133 additions and 37 deletions

View File

@ -1,6 +1,7 @@
//FieldNameTable
ModelNameColumn:= TableNameForeign.ModelNameForeign{}
ModelNameColumn.PrimaryKeyNameF = m.FieldNameTable
ModelNameColumnID := m.FieldNameTable
ModelNameColumn.PrimaryKeyNameFK = IntFromAlias(ModelNameColumnID)
err = crud_TableNameForeign.Read_ctx(ctx, db, &ModelNameColumn)
if err != nil {
err = fmt.Errorf(ModelNameColumn.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithCommaM, err)

View File

@ -395,9 +395,9 @@ func Replace_PrimaryKeyOtvetID_ManyPK1(Text string, Table1 *types.Table, Variabl
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"
@ -422,7 +422,7 @@ func Replace_PrimaryKeyOtvetID_ManyPK1(Text string, Table1 *types.Table, Variabl
Otvet = strings.ReplaceAll(Otvet, "\tm2.ID = int64(m.ID)", TextM2ID)
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", TextIfMId)
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", TextIfMIdNot0)
//Value := Convert_GolangVariableToProtobufVariable(Table1, ColumnPK, "m")
//Value := Convert_GolangVariableToProtobufVariableID(Table1, ColumnPK, "m")
//Otvet = strings.ReplaceAll(Otvet, "ProtoFromInt(m.ID)", Value) //protobuf
//заменим ID := Request.ID
@ -457,14 +457,14 @@ func Replace_PrimaryKeyM_ManyPK(Text string, Table1 *types.Table) string {
func ReplaceIntFromAlias(Text string, Table1 *types.Table, Column1 *types.Column, VariableName string) string {
Otvet := Text
Value := ConvertFromAlias(Table1, Column1, VariableName)
Value := ConvertFromAliasID(Table1, Column1, VariableName)
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias("+VariableName+".ID)", Value)
return Otvet
}
// ConvertFromAlias - возвращает текст m.ID или int64(m.ID)
func ConvertFromAlias(Table1 *types.Table, Column1 *types.Column, VariableName string) string {
// ConvertFromAliasID - возвращает текст m.ID или int64(m.ID)
func ConvertFromAliasID(Table1 *types.Table, Column1 *types.Column, VariableName string) string {
Otvet := VariableName + "." + Column1.NameGo
TextConvert, ok := types.MapConvertID[Table1.Name+"."+Column1.Name]
@ -481,6 +481,24 @@ func ConvertFromAlias(Table1 *types.Table, Column1 *types.Column, VariableName s
return Otvet
}
// ConvertFromAlias - возвращает текст VariableName или int64(VariableName)
func ConvertFromAlias(Table1 *types.Table, Column1 *types.Column, VariableName string) string {
Otvet := VariableName
TextConvert, ok := types.MapConvertID[Table1.Name+"."+Column1.Name]
if ok == false {
return Otvet
}
if TextConvert[:6] != "alias." {
return Otvet
}
Otvet = Column1.TypeGo + "(" + VariableName + ")"
return Otvet
}
// AddSkipNow - добавляет строку t.SkipNow()
func AddSkipNow(Text string, Table1 *types.Table) string {
Otvet := Text
@ -1755,8 +1773,8 @@ func DeleteCommentFromString(TextFrom string) string {
return Otvet
}
// Convert_GolangVariableToProtobufVariable - возвращает имя переменной + "." + имя колонки, преобразованное в тип protobuf
func Convert_GolangVariableToProtobufVariable(Table1 *types.Table, Column1 *types.Column, VariableName string) string {
// Convert_GolangVariableToProtobufVariableID - возвращает имя переменной + "." + имя колонки, преобразованное в тип protobuf
func Convert_GolangVariableToProtobufVariableID(Table1 *types.Table, Column1 *types.Column, VariableName string) string {
Otvet := ""
if Column1 == nil {
@ -1817,6 +1835,73 @@ func Convert_GolangVariableToProtobufVariable(Table1 *types.Table, Column1 *type
return Otvet
}
// Convert_GolangVariableToProtobufVariableType - возвращает имя переменной преобразованное в тип protobuf
func Convert_GolangVariableToProtobufVariableType(Table1 *types.Table, Column1 *types.Column, VariableName, VariableType string) string {
Otvet := VariableName
if Column1 == nil {
return Otvet
}
//Dot := ""
//if VariableName != "" {
// Dot = "."
//}
//Otvet = VariableName + Dot + Column1.NameGo
//найдём alias
_, HasAlias := types.MapConvertID[Table1.Name+"."+Column1.Name]
TextVariableName := VariableName
if VariableType != Column1.TypeGo {
TextVariableName = VariableType + "(" + VariableName + ")"
}
//преобразуем alias в обычный тип, и дату в timestamp
if HasAlias == true {
switch Column1.TypeGo {
case "time.Time":
Otvet = "timestamppb.New(" + VariableName + ")"
case "string":
Otvet = VariableType + "(" + VariableName + ")"
case "int64":
Otvet = VariableType + "(" + VariableName + ")"
case "int32":
Otvet = VariableType + "(" + VariableName + ")"
case "bool":
Otvet = VariableType + "(" + VariableName + ")"
case "float32":
Otvet = VariableType + "(" + VariableName + ")"
case "float64":
Otvet = VariableType + "(" + VariableName + ")"
case "uuid.UUID":
Otvet = VariableName + ".String()"
}
} else {
switch Column1.TypeGo {
case "time.Time":
Otvet = "timestamppb.New(" + VariableName + ")"
case "string":
Otvet = TextVariableName
case "int64":
Otvet = TextVariableName
case "int32":
Otvet = TextVariableName
case "bool":
Otvet = TextVariableName
case "float32":
Otvet = TextVariableName
case "float64":
Otvet = TextVariableName
case "uuid.UUID":
Otvet = VariableName + ".String()"
}
}
return Otvet
}
//// ConvertVariableToProtobufType - возвращает имя переменной + имя колонки, преобразованное в тип protobuf
//func ConvertVariableToProtobufType(Column1 *types.Column, VariableName string) string {
// Otvet := ""
@ -2276,7 +2361,7 @@ func FindText_IDMany(Table1 *types.Table) (TextNames, TextNamesTypes, TextProtoN
//Comma := ""
//MassPrimaryKey := Find_PrimaryKeyColumns(Table1)
//for _, PrimaryKey1 := range MassPrimaryKey {
// OtvetColumnName := Convert_GolangVariableToProtobufVariable(Table1, PrimaryKey1, "")
// OtvetColumnName := Convert_GolangVariableToProtobufVariableID(Table1, PrimaryKey1, "")
// if OtvetColumnName == "" {
// continue
// }
@ -2304,7 +2389,7 @@ func FindText_ID_VariableName_Many(Table1 *types.Table, VariableName string) (Te
Comma := ""
MassPrimaryKey := Find_PrimaryKeyColumns(Table1)
for _, PrimaryKey1 := range MassPrimaryKey {
OtvetColumnName := Convert_GolangVariableToProtobufVariable(Table1, PrimaryKey1, "")
OtvetColumnName := Convert_GolangVariableToProtobufVariableID(Table1, PrimaryKey1, "")
if OtvetColumnName == "" {
continue
}

View File

@ -1,6 +1,7 @@
package crud_object_tables
import (
"fmt"
"github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/types"
@ -139,6 +140,11 @@ func CreateFiles_ReadObjectTable(MapAll map[string]*types.Table, Table1 *types.T
}
TableF, _ := create_files.Find_TableF_ColumnF(MapAll, Column1)
if TableF == nil {
err := fmt.Errorf("Find_TableF_ColumnF() error: Foreign table for column %s not found", Column1.Name)
log.Error(err)
break
}
TableNameF := TableF.Name
//шаблон функции
@ -171,9 +177,13 @@ func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types
TableFK, ColumnFK := create_files.Find_TableF_ColumnF(MapAll, Column1)
ColumnPKF := create_files.Find_PrimaryKeyColumn(TableFK)
//PrimaryKeyNameF
PrimaryKeyNameF := ColumnPKF.NameGo
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNameF", PrimaryKeyNameF)
//IntFromAlias
IntFromAlias := create_files.Convert_GolangVariableToProtobufVariableType(Table1, Column1, "ModelNameColumnID", ColumnFK.TypeGo)
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(ModelNameColumnID)", IntFromAlias)
//PrimaryKeyNameFK
PrimaryKeyNameFK := ColumnPKF.NameGo
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNameFK", PrimaryKeyNameFK)
//FieldNameForeign
FieldNameForeign := ColumnFK.NameGo

View File

@ -183,7 +183,7 @@ func ReplaceCacheRemove_1PK(Text string, Table1 *types.Table) string {
ColumnPK := create_files.Find_PrimaryKeyColumn(Table1)
TextOld := "cache.Remove(IntFromAlias(m.ID))"
Value := create_files.ConvertFromAlias(Table1, ColumnPK, "m")
Value := create_files.ConvertFromAliasID(Table1, ColumnPK, "m")
TextNew := "cache.Remove(" + Value + ")"
Otvet = strings.ReplaceAll(Otvet, TextOld, TextNew)

View File

@ -411,9 +411,9 @@ func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"

View File

@ -376,9 +376,9 @@ func Replace_PrimaryKeyOtvetID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"

View File

@ -175,9 +175,9 @@ func Replace_PrimaryKeyM_ID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"
@ -240,9 +240,9 @@ func Replace_PrimaryKeyOtvetID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDVariableID = TextOtvetIDVariableID + "\t" + VariableName + "." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + VariableName + "." + Column1.NameGo + " = m." + Column1.NameGo + "\n"
@ -316,9 +316,9 @@ func Replace_PrimaryKeyRequest_ID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"

View File

@ -153,7 +153,7 @@ func CreateFiles_FindByTable1(Table1 *types.Table, TextTemplateFunction string,
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
}
TextRequest := create_files.Find_RequestFieldName_FromMass(Column1, MassColumns)
ValueM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
ValueM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextAssign = TextAssign + "\tRequest." + TextRequest + " = " + ValueM + "\n"
ColumnNameTranslit := Column1.NameGo
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + ColumnNameTranslit

View File

@ -147,7 +147,7 @@ func CreateFiles_FindModelByTable1(MapAll map[string]*types.Table, Table1 *types
//RequestName := "Request_"
RequestName := create_files.FindText_ProtobufRequest_Column_ManyPK(Table1, Column1)
//TextRequest := create_files.Find_RequestFieldName(Table1, Column1)
//ValueM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
//ValueM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
//TextAssign = TextAssign + "\tRequest." + TextRequest + " = " + ValueM + "\n"
ColumnNameTranslit := Column1.NameGo
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + ColumnNameTranslit
@ -188,7 +188,7 @@ func CreateFiles_FindModelByTable1(MapAll map[string]*types.Table, Table1 *types
MassPK := create_files.Find_PrimaryKeyColumns(Table1)
MassPK_and_Column := create_files.AppendColumn(MassPK, Column1)
for _, ColumnPK1 := range MassPK_and_Column {
RequestColumnName := create_files.Convert_GolangVariableToProtobufVariable(Table1, ColumnPK1, "m")
RequestColumnName := create_files.Convert_GolangVariableToProtobufVariableID(Table1, ColumnPK1, "m")
//TextIDEqual = TextIDEqual + "\t" + ColumnPK1.NameGo + " := m." + ColumnPK1.NameGo + "\n"
TextRequest := create_files.Find_RequestFieldName(Table1, ColumnPK1)
TextRequestColumnName = TextRequestColumnName + "\t" + "Request." + TextRequest + " = " + RequestColumnName + "\n"

View File

@ -166,7 +166,7 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types.
Otvet = Replace_PrimaryKeyM_ID(Otvet, Table1)
//
ColumnNameGolang := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
ColumnNameGolang := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
_, IDTypeGo := create_files.Find_PrimaryKeyNameTypeGo(Table1)

View File

@ -195,7 +195,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 := Convert_GolangVariableToProtobufVariable(Table1, Column1, VariableName)
//Text1 := Convert_GolangVariableToProtobufVariableID(Table1, Column1, VariableName)
RequestColumnName := create_files.Find_RequestFieldName(Table1, Column1)
TextNew = TextNew + "\tRequest." + RequestColumnName + " = " + VariableName + "\n"
}
@ -207,7 +207,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 := Convert_GolangVariableToProtobufVariable(Table1, Column1, VariableName)
//Text1 := Convert_GolangVariableToProtobufVariableID(Table1, Column1, VariableName)
RequestColumnName := create_files.Find_RequestFieldName(Table1, Column1)
TextNew = TextNew + "\tRequest2." + RequestColumnName + " = " + VariableName + "\n"
}

View File

@ -358,9 +358,9 @@ func Replace_PrimaryKeyM_ID(Text string, Table1 *types.Table) string {
} else {
TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
}
TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"
@ -421,9 +421,9 @@ func Replace_PrimaryKeyM_ID(Text string, Table1 *types.Table) string {
// } else {
// TextIDRequestID = TextIDRequestID + "\t" + GolangCode + "\n"
// }
// TextM := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
// TextM := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
// TextRequestIDmID = TextRequestIDmID + "\t" + VariableName + "." + RequestColumnName + " = " + TextM + "\n"
// TextInt64ID := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "")
// TextInt64ID := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "")
// TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n"
// TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n"
//

View File

@ -153,7 +153,7 @@ func FindText_UpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.
//Otvet = create_files.Replace_PrimaryKeyOtvetID(Otvet, Table1)
Otvet = Replace_PrimaryKeyM_ID(Otvet, Table1)
//ColumnNameGolang := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
//ColumnNameGolang := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update", ModelNameTranslit+"_"+FuncName)
@ -340,7 +340,7 @@ func FindText_UpdateEveryColumn_Test1(TextGRPCServerUpdateFunc string, Table1 *t
ColumnNameTranslit := Column1.NameGo_translit
FuncName := "Update_" + ColumnNameTranslit
_, TextRequestField, TextRequestFieldGolang, _ := create_files.FindText_ProtobufRequest_ID_Type(Table1, Column1, "Request2.")
TextModelColumnName := create_files.Convert_GolangVariableToProtobufVariable(Table1, Column1, "m")
TextModelColumnName := create_files.Convert_GolangVariableToProtobufVariableID(Table1, Column1, "m")
TextRequestID := create_files.FindText_ProtobufRequest_ManyPK(Table1)
//Postgres_ID_Test = ID Minimum