You've already forked crud_generator
							
							
				mirror of
				https://github.com/ManyakRus/crud_generator.git
				synced 2025-10-31 00:17:48 +02:00 
			
		
		
		
	сделал notifier без ошибок
This commit is contained in:
		| @@ -264,6 +264,7 @@ func ReplacePrimaryKeyOtvetID1(Text string, Table1 *types.Table) string { | |||||||
| 	Otvet := Text | 	Otvet := Text | ||||||
|  |  | ||||||
| 	ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1) | 	ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1) | ||||||
|  | 	ColumnPK := FindPrimaryKeyColumn(Table1) | ||||||
|  |  | ||||||
| 	//заменим ID-Alias на ID | 	//заменим ID-Alias на ID | ||||||
| 	TableName := Table1.Name | 	TableName := Table1.Name | ||||||
| @@ -308,6 +309,15 @@ func ReplacePrimaryKeyOtvetID1(Text string, Table1 *types.Table) string { | |||||||
| 		Otvet = strings.ReplaceAll(Otvet, "AliasFromInt(ID)", "ID") | 		Otvet = strings.ReplaceAll(Otvet, "AliasFromInt(ID)", "ID") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	Value, GolangCode := ConvertProtobufTypeToGolangType(Table1, ColumnPK, "Request.") | ||||||
|  | 	if GolangCode == "" { | ||||||
|  | 		TextNew := "\t" + ColumnPK.NameGo + " := " + Value + "\n" | ||||||
|  | 		Otvet = strings.ReplaceAll(Otvet, "\tID := Request.ID\n", TextNew) | ||||||
|  | 	} else { | ||||||
|  | 		TextNew := "\t" + GolangCode + "\n" | ||||||
|  | 		Otvet = strings.ReplaceAll(Otvet, "\tID := Request.ID\n", TextNew) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return Otvet | 	return Otvet | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1841,19 +1851,17 @@ func ConvertGolangTypeToProtobufType(Table1 *types.Table, Column1 *types.Column, | |||||||
|  |  | ||||||
| // ConvertProtobufTypeToGolangType - возвращает имя переменной +  имя колонки, преобразованное в тип golang из protobuf | // ConvertProtobufTypeToGolangType - возвращает имя переменной +  имя колонки, преобразованное в тип golang из protobuf | ||||||
| func ConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types.Column, VariableName string) (VariableColumn string, GolangCode string) { | func ConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types.Column, VariableName string) (VariableColumn string, GolangCode string) { | ||||||
| 	VariableColumn = VariableName + Column1.NameGo | 	RequestColumnName := FindRequestColumnName(Table1, Column1) | ||||||
|  | 	VariableColumn = VariableName + RequestColumnName | ||||||
| 	//GolangCode := "" | 	//GolangCode := "" | ||||||
|  |  | ||||||
| 	TableName := Table1.Name | 	TableName := Table1.Name | ||||||
| 	IDName := Column1.Name | 	IDName := Column1.Name | ||||||
|  |  | ||||||
| 	RequestColumnName := Column1.NameGo |  | ||||||
| 	RequestColumnName = FindRequestColumnName(Table1, Column1) |  | ||||||
|  |  | ||||||
| 	//alias в Int64 | 	//alias в Int64 | ||||||
| 	TextConvert, ok := types.MapConvertID[TableName+"."+IDName] | 	TextConvert, ok := types.MapConvertID[TableName+"."+IDName] | ||||||
| 	if ok == true { | 	if ok == true { | ||||||
| 		VariableColumn = TextConvert + "(" + VariableName + Column1.NameGo + ")" | 		VariableColumn = TextConvert + "(" + VariableName + RequestColumnName + ")" | ||||||
| 		return VariableColumn, GolangCode | 		return VariableColumn, GolangCode | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -1861,7 +1869,7 @@ func ConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types.Column, | |||||||
| 	switch Column1.TypeGo { | 	switch Column1.TypeGo { | ||||||
| 	case "time.Time": | 	case "time.Time": | ||||||
| 		{ | 		{ | ||||||
| 			VariableColumn = VariableName + Column1.NameGo + ".AsTime()" | 			VariableColumn = VariableName + RequestColumnName + ".AsTime()" | ||||||
| 			return VariableColumn, GolangCode | 			return VariableColumn, GolangCode | ||||||
| 		} | 		} | ||||||
| 	case "uuid.UUID": | 	case "uuid.UUID": | ||||||
| @@ -1875,28 +1883,6 @@ func ConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types.Column, | |||||||
| 			return VariableColumn, GolangCode | 			return VariableColumn, GolangCode | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	//if Column1.TypeGo == "time.Time" { |  | ||||||
| 	//	VariableColumn = VariableName + Column1.NameGo + ".AsTime()" |  | ||||||
| 	//	return VariableColumn |  | ||||||
| 	//} |  | ||||||
|  |  | ||||||
| 	////преобразуем alias в обычный тип, и дату в timestamp |  | ||||||
| 	//switch Column1.TypeGo { |  | ||||||
| 	//case "time.Time": |  | ||||||
| 	//	VariableColumn = "timestamppb.New(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "string": |  | ||||||
| 	//	VariableColumn = "string(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "int64": |  | ||||||
| 	//	VariableColumn = "int64(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "int32": |  | ||||||
| 	//	VariableColumn = "int32(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "bool": |  | ||||||
| 	//	VariableColumn = "bool(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "float32": |  | ||||||
| 	//	VariableColumn = "float32(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//case "float64": |  | ||||||
| 	//	VariableColumn = "float64(" + VariableName + Column1.NameGo + ")" |  | ||||||
| 	//} |  | ||||||
|  |  | ||||||
| 	return VariableColumn, GolangCode | 	return VariableColumn, GolangCode | ||||||
| } | } | ||||||
| @@ -2653,3 +2639,17 @@ func ReplaceCacheRemove_ManyPK(Text string, Table1 *types.Table) string { | |||||||
|  |  | ||||||
| 	return Otvet | 	return Otvet | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsPrimaryKeyColumn - проверяет является ли колонка PrimaryKey | ||||||
|  | func IsPrimaryKeyColumn(Table1 *types.Table, Column *types.Column) bool { | ||||||
|  | 	Otvet := false | ||||||
|  |  | ||||||
|  | 	for _, Column1 := range Table1.MapColumns { | ||||||
|  | 		if Column1.IsPrimaryKey == true && Column1 == Column { | ||||||
|  | 			Otvet = true | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return Otvet | ||||||
|  | } | ||||||
|   | |||||||
| @@ -127,11 +127,16 @@ func CreateFiles(Table1 *types.Table) error { | |||||||
| 		CrudTableURL := create_files.FindCrudTableURL(TableName) | 		CrudTableURL := create_files.FindCrudTableURL(TableName) | ||||||
| 		TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudTableURL) | 		TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudTableURL) | ||||||
|  |  | ||||||
| 		TextGRPCServer = ReplaceIDRequestID_1PK(TextGRPCServer, Table1) | 		if Table1.PrimaryKeyColumnsCount == 1 { | ||||||
|  | 			TextGRPCServer = ReplaceIDRequestID_1PK(TextGRPCServer, Table1) | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		//замена ID на PrimaryKey | 		//замена "m.ID = AliasFromInt(ID)" | ||||||
| 		TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1) | 		TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
|  | 		//замена "ID := Request.ID" | ||||||
|  | 		TextGRPCServer = create_files.ReplacePrimaryKeyOtvetID(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
| 		//замена RequestId{} | 		//замена RequestId{} | ||||||
| 		TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1) | 		TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
| @@ -522,7 +527,8 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T | |||||||
| 	_, _, TextRequestFieldGolang, TextGolangLine := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.") | 	_, _, TextRequestFieldGolang, TextGolangLine := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.") | ||||||
| 	//if Table1.PrimaryKeyColumnsCount > 1 { | 	//if Table1.PrimaryKeyColumnsCount > 1 { | ||||||
| 	TextRequest := create_files.FindTextProtobufRequest_Column_ManyPK(Table1, Column1) | 	TextRequest := create_files.FindTextProtobufRequest_Column_ManyPK(Table1, Column1) | ||||||
| 	ColumnPK := create_files.FindPrimaryKeyColumn(Table1) | 	//ColumnPK := create_files.FindPrimaryKeyColumn(Table1) | ||||||
|  | 	IsPrimaryKey := create_files.IsPrimaryKeyColumn(Table1, Column1) | ||||||
|  |  | ||||||
| 	//замена ID на PrimaryKey | 	//замена ID на PrimaryKey | ||||||
| 	Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) | 	Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) | ||||||
| @@ -532,7 +538,7 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T | |||||||
| 	Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update", ModelName+"_"+FuncName) | 	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_MODEL, ModelName) | ||||||
| 	Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) | 	Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) | ||||||
| 	if Column1 == ColumnPK { | 	if IsPrimaryKey == true { | ||||||
| 		Otvet = strings.ReplaceAll(Otvet, "\tColumnName := Request.FieldName\n", "") | 		Otvet = strings.ReplaceAll(Otvet, "\tColumnName := Request.FieldName\n", "") | ||||||
| 	} else if TextGolangLine != "" { | 	} else if TextGolangLine != "" { | ||||||
| 		Otvet = strings.ReplaceAll(Otvet, "ColumnName := Request.FieldName", TextGolangLine) | 		Otvet = strings.ReplaceAll(Otvet, "ColumnName := Request.FieldName", TextGolangLine) | ||||||
| @@ -780,16 +786,17 @@ func CreateFilesCache(Table1 *types.Table) error { | |||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	TextGRPCServer = create_files.ReplacePrimaryKeyOtvetID(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
|  | 	TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
| 	if Table1.PrimaryKeyColumnsCount == 1 { | 	if Table1.PrimaryKeyColumnsCount == 1 { | ||||||
| 	} else { | 	} else { | ||||||
| 		TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1) |  | ||||||
| 		TextIDMany := ", ID)" | 		TextIDMany := ", ID)" | ||||||
| 		TextIDMany = create_files.ReplaceIDtoID_Many(TextIDMany, Table1) | 		TextIDMany = create_files.ReplaceIDtoID_Many(TextIDMany, Table1) | ||||||
| 		TextGRPCServer = strings.ReplaceAll(TextGRPCServer, "(ID)", "("+Table1.Name+".StringIdentifier"+TextIDMany+")") | 		TextGRPCServer = strings.ReplaceAll(TextGRPCServer, "(ID)", "("+Table1.Name+".StringIdentifier"+TextIDMany+")") | ||||||
| 		TextGRPCServer = create_files.ReplaceIDtoID_Many(TextGRPCServer, Table1) |  | ||||||
| 		//замена ID на PrimaryKey |  | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  | 	TextGRPCServer = create_files.ReplaceIDtoID_Many(TextGRPCServer, Table1) | ||||||
|  |  | ||||||
| 	//замена RequestId{} | 	//замена RequestId{} | ||||||
| 	TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1) | 	TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user