mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-24 08:22:42 +02:00
сделал CreateFilesUpdateEveryColumn()
This commit is contained in:
parent
b37b6bac7c
commit
e8c7884efe
@ -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)
|
||||
}
|
||||
|
@ -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 := ""
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user