From 64ca01f6935dca79508b7e3799bc6f13f13c75b2 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 15 May 2024 17:12:03 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20constant?= =?UTF-8?q?s=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/grpc/server_grpc/server_grpc.go_ | 6 +- .../pkg/db/crud/crud_table_cache.go_ | 2 +- .../pkg/db/crud/crud_table_update.go_ | 2 +- .../pkg/db/crud/crud_table_update_func.go_ | 6 +- bin/templates/pkg/db/crud/crud_tables.go_ | 4 +- .../pkg/db/crud/crud_tables_rapira.go_ | 8 +-- .../grpc/grpc_client/grpc_client_table.go_ | 6 +- .../grpc_client_table_cache_test.go_ | 2 +- .../grpc_client/grpc_client_table_test.go_ | 21 +++--- .../grpc_client_table_update_func.go_ | 2 +- .../grpc_client_table_update_func_test.go_ | 2 +- .../grpc_client_table_update_test.go_ | 2 +- .../grpc/grpc_client/grpc_client_test.go_ | 4 +- internal/constants/constants.go | 2 +- internal/create_files/create_files.go | 64 +++++++++++++------ .../create_files/crud_tables/crud_tables.go | 3 + .../grpc_client_tables/grpc_client_tables.go | 6 +- 17 files changed, 82 insertions(+), 60 deletions(-) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ index c38e458..b1d819b 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ @@ -32,7 +32,7 @@ func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_p db := postgres_gorm.GetConnection() ID := Request.ID m := &lawsuit_status_types.LawsuitStatusType{} - m.ID = ID + m.ID = IntToAlias(ID) err = crud_lawsuit_status_types.Read_ctx(ctx, db, m) if err != nil { return &Otvet, err @@ -71,7 +71,7 @@ func (s *ServerGRPC) LawsuitStatusType_Delete(ctx context.Context, Request *grpc db := postgres_gorm.GetConnection() ID := Request.ID m := &lawsuit_status_types.LawsuitStatusType{} - m.ID = ID + m.ID = IntToAlias(ID) err = crud_lawsuit_status_types.Delete_ctx(ctx, db, m) if err != nil { return &Otvet, err @@ -110,7 +110,7 @@ func (s *ServerGRPC) LawsuitStatusType_Restore(ctx context.Context, Request *grp db := postgres_gorm.GetConnection() ID := Request.ID m := &lawsuit_status_types.LawsuitStatusType{} - m.ID = ID + m.ID = IntToAlias(ID) err = crud_lawsuit_status_types.Restore_ctx(ctx, db, m) if err != nil { return &Otvet, err diff --git a/bin/templates/pkg/db/crud/crud_table_cache.go_ b/bin/templates/pkg/db/crud/crud_table_cache.go_ index 16b33c9..2512feb 100644 --- a/bin/templates/pkg/db/crud/crud_table_cache.go_ +++ b/bin/templates/pkg/db/crud/crud_table_cache.go_ @@ -54,7 +54,7 @@ func ReadFromCache_ctx(ctx context.Context, db *gorm.DB, ID int64) (lawsuit_stat var err error - Otvet.ID = ID + Otvet.ID = IntToAlias(ID) err = Read_ctx(ctx, db, &Otvet) if err == nil { cache.Add(ID, Otvet) diff --git a/bin/templates/pkg/db/crud/crud_table_update.go_ b/bin/templates/pkg/db/crud/crud_table_update.go_ index e9cf7b8..ef58a3a 100644 --- a/bin/templates/pkg/db/crud/crud_table_update.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update.go_ @@ -38,7 +38,7 @@ func UpdateManyFields_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_ty return err } - if int64(m.ID) == 0 { + if IntFromAlias(m.ID) == 0 { err = errors.New(m.TableNameDB() + " UpdateManyFields() error: ID=0") return err } diff --git a/bin/templates/pkg/db/crud/crud_table_update_func.go_ b/bin/templates/pkg/db/crud/crud_table_update_func.go_ index 5e56f13..6d12cc9 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_func.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_func.go_ @@ -23,7 +23,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS } //ID не должен быть =0 - if int64(m.ID) == 0 { + if IntFromAlias(m.ID) == 0 { err = errors.New(m.TableNameDB()+" Read() error: ID=0") return err } @@ -41,12 +41,12 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS } err = tx.Error if err != nil { - err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", IntFromAlias(m.ID), err) return err } //удалим из кэша - cache.Remove(m.ID) + cache.Remove(IntFromAlias(m.ID)) return err } diff --git a/bin/templates/pkg/db/crud/crud_tables.go_ b/bin/templates/pkg/db/crud/crud_tables.go_ index adba5e3..3129e82 100644 --- a/bin/templates/pkg/db/crud/crud_tables.go_ +++ b/bin/templates/pkg/db/crud/crud_tables.go_ @@ -189,14 +189,14 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types tx = tx.Omit(MassOmit...) // запись - tx = tx.Create(&m) + tx = tx.Save(&m) err = tx.Error if err != nil { return err } //удалим из кэша - //cache.Remove(m.ID) + //cache.Remove(IntFromAlias(m.ID)) //запишем NULL в пустые колонки MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit) diff --git a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ index 1e7da87..b591fd7 100644 --- a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ @@ -189,14 +189,14 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types tx = tx.Omit(MassOmit...) // запись - tx = tx.Create(&m) + tx = tx.Save(&m) err = tx.Error if err != nil { return err } //удалим из кэша - //cache.Remove(m.ID) + //cache.Remove(IntFromAlias(m.ID)) //запишем NULL в пустые колонки MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit) @@ -237,7 +237,7 @@ func Delete_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui } m2 := lawsuit_status_types.LawsuitStatusType{} - m2.ID = int64(m.ID) + m2.ID = m.ID err = Read_ctx(ctx, db, &m2) if err != nil { return err @@ -278,7 +278,7 @@ func Restore_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsu } m2 := lawsuit_status_types.LawsuitStatusType{} - m2.ID = int64(m.ID) + m2.ID = m.ID err = Read_ctx(ctx, db, &m2) if err != nil { return err diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ index 18c06ef..2ef761d 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ @@ -50,7 +50,7 @@ func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { var versionModel = crud.GetVersionModel() Request := &grpc_proto.RequestId{} - Request.ID = int64(m.ID) + Request.ID = IntFromAlias(m.ID) Request.VersionModel = versionModel ctxMain := context.Background() @@ -230,7 +230,7 @@ func (crud Crud_GRPC) Delete(m *lawsuit_status_types.LawsuitStatusType) error { var VersionModel = crud.GetVersionModel() Request := &grpc_proto.RequestId{} - Request.ID = int64(m.ID) + Request.ID = IntFromAlias(m.ID) Request.VersionModel = VersionModel ctxMain := context.Background() @@ -272,7 +272,7 @@ func (crud Crud_GRPC) Restore(m *lawsuit_status_types.LawsuitStatusType) error { var VersionModel = crud.GetVersionModel() Request := &grpc_proto.RequestId{} - Request.ID = int64(m.ID) + Request.ID = IntFromAlias(m.ID) Request.VersionModel = VersionModel ctxMain := context.Background() diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ index 5bcc530..d3cd999 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ @@ -20,7 +20,7 @@ func TestReadFromCache(t *testing.T) { t.Error("ReadFromCache() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("ReadFromCache() error: ID =0") } } diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ index be599a9..94c1b15 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ @@ -33,7 +33,7 @@ func TestRead(t *testing.T) { t.Error("TestRead() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestRead() error: ID =0") } } @@ -53,9 +53,6 @@ func TestCreate(t *testing.T) { t.Error("TestCreate() error: ", err) } - if int64(Otvet.ID) != 0 { - t.Error("TestCreate() error: ID !=0") - } } func TestUpdate(t *testing.T) { @@ -64,7 +61,7 @@ func TestUpdate(t *testing.T) { defer grpc_client.CloseConnection() Otvet := lawsuit_status_types.LawsuitStatusType{} - Otvet.ID = -1 + Otvet.ID = 0 crud := Crud_GRPC{} err := crud.Update(&Otvet) @@ -73,7 +70,7 @@ func TestUpdate(t *testing.T) { t.Error("TestUpdate() error: ", err) } - if int64(Otvet.ID) != 0 { + if IntFromAlias(Otvet.ID) != 0 { t.Error("TestUpdate() error: ID =0") } } @@ -98,7 +95,7 @@ func TestSave(t *testing.T) { t.Error("TestSave() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestSave() error: ID =0") } } @@ -121,7 +118,7 @@ func TestDelete(t *testing.T) { if err != nil { t.Error("TestDelete() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestDelete() error: ID =0") } @@ -129,7 +126,7 @@ func TestDelete(t *testing.T) { if err != nil { t.Error("TestDelete() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestDelete() error: ID =0") } } else { @@ -137,7 +134,7 @@ func TestDelete(t *testing.T) { if err != nil { t.Error("TestDelete() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestDelete() error: ID =0") } @@ -145,7 +142,7 @@ func TestDelete(t *testing.T) { if err != nil { t.Error("TestDelete() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestDelete() error: ID =0") } } @@ -178,7 +175,7 @@ func TestFindByExtID(t *testing.T) { t.Error("TestFindByExtID() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestFindByExtID() error: ID =0") } } diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ index ce3d883..bafcee7 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ @@ -9,7 +9,7 @@ func (crud Crud_GRPC) Update(m *lawsuit_status_types.LawsuitStatusType) error { var versionModel = crud.GetVersionModel() Request := &grpc_proto.RequestId{} - Request.ID = int64(m.ID) + Request.ID = IntFromAlias(m.ID) Request.FieldName = m.ColumnName Request.VersionModel = versionModel diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ index f2e6e20..9aceaf1 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ @@ -1,7 +1,7 @@ func TestCrud_GRPC_Update(t *testing.T) { config_main.LoadEnv() - postgres_gorm.Connect_WithApplicationName(constants.SERVICE_NAME + "_test") + grpc_client.Connect() defer grpc_client.CloseConnection() crud := Crud_GRPC{} diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ index 2ae05d3..7a4aec5 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ @@ -29,7 +29,7 @@ func TestCrud_GRPC_UpdateManyFields(t *testing.T) { t.Error("TestCrud_GRPC_UpdateManyFields() error: ", err) } - if int64(Otvet.ID) == 0 { + if IntFromAlias(Otvet.ID) == 0 { t.Error("TestCrud_GRPC_UpdateManyFields() error: ID =0") } } diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_test.go_ index cf46fa7..5816b38 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_test.go_ @@ -2,13 +2,13 @@ package grpc_client import ( "errors" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "testing" ) func TestIsRecordNotFound(t *testing.T) { - err := errors.New(constants.TEXT_RECORD_NOT_FOUND + " !") + err := errors.New(db_constants.TEXT_RECORD_NOT_FOUND + " !") Otvet := IsRecordNotFound(err) if Otvet != true { t.Error("TestIsRecordNotFound() error: false") diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 4d17220..a799035 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -56,7 +56,7 @@ const GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME = "grpc_client_table_update_fu const CRUD_TABLES_CACHE_FILENAME = "crud_table_cache.go_" const CRUD_TABLES_CACHE_TEST_FILENAME = "crud_table_cache_test.go_" -const TEXT_CACHE_REMOVE = "cache.Remove(m.ID)" +const TEXT_CACHE_REMOVE = "cache.Remove(" const SERVER_GRPC_TABLE_CACHE_FILENAME = "server_grpc_table_cache.go_" const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_" diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 667e560..b12a472 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -191,36 +191,48 @@ func FindPrimaryKeyColumn(Table1 *types.Table) (Column1 *types.Column) { func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string { Otvet := Text - ColumnName, ColumnTypeGo := FindPrimaryKeyNameTypeGo(Table1) + ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1) //заменим ID-Alias на ID TableName := Table1.Name IDName, _ := FindPrimaryKeyNameType(Table1) - _, ok := types.MapConvertID[TableName+"."+IDName] - OtvetColumnName := "Otvet." + ColumnName + Alias, ok := types.MapConvertID[TableName+"."+IDName] + OtvetColumnName := "Otvet." + ColumnNamePK if ok == true { - OtvetColumnName = ColumnTypeGo + "(" + OtvetColumnName + ")" + OtvetColumnName = Alias + "(" + OtvetColumnName + ")" } //заменим int64(Otvet.ID) на Otvet.ID - if mini_func.IsNumberType(ColumnTypeGo) == true { + if mini_func.IsNumberType(ColumnTypeGoPK) == true { Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName) - } else if ColumnTypeGo == "string" { + } else if ColumnTypeGoPK == "string" { Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == \"\"") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != \"\"") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName) - } else if ColumnTypeGo == "uuid.UUID" || ColumnTypeGo == "uuid.NullUUID" { + } else if ColumnTypeGoPK == "uuid.UUID" || ColumnTypeGoPK == "uuid.NullUUID" { Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == uuid.Nil") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != uuid.Nil") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName) - } else if ColumnTypeGo == "time.Time" { + } else if ColumnTypeGoPK == "time.Time" { Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+".IsZero() == true") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+".IsZero() == false") Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName) } - Otvet = strings.ReplaceAll(Otvet, "Otvet.ID = ", OtvetColumnName+" = ") - Otvet = strings.ReplaceAll(Otvet, "Otvet.ID != ", OtvetColumnName+" != ") - Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " "+OtvetColumnName+")") + //Otvet = strings.ReplaceAll(Otvet, "Otvet.ID = ", OtvetColumnName+" = ") + //Otvet = strings.ReplaceAll(Otvet, "Otvet.ID != ", OtvetColumnName+" != ") + //Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " "+OtvetColumnName+")") + Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " Otvet."+ColumnNamePK+")") + + //Alias преобразуем в int64, и наоборот + if Alias != "" { + Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(Otvet.ID)", ColumnTypeGoPK+"(Otvet."+ColumnNamePK+")") + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(Otvet.ID)", OtvetColumnName) + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", Alias+"("+ColumnNamePK+")") + } else { + Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(Otvet.ID)", "Otvet."+ColumnNamePK+"") + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(Otvet.ID)", OtvetColumnName) + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", "ID") + } return Otvet } @@ -229,38 +241,48 @@ func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string { func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string { Otvet := Text - ColumnName, ColumnTypeGo := FindPrimaryKeyNameTypeGo(Table1) + ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1) //заменим ID-Alias на ID TableName := Table1.Name IDName, _ := FindPrimaryKeyNameType(Table1) Alias, ok := types.MapConvertID[TableName+"."+IDName] - OtvetColumnName := "m." + ColumnName + OtvetColumnName := "m." + ColumnNamePK if ok == true { OtvetColumnName = Alias + "(" + OtvetColumnName + ")" - //OtvetColumnName = ColumnTypeGo + "(" + OtvetColumnName + ")" } //заменим int64(m.ID) на m.ID - if mini_func.IsNumberType(ColumnTypeGo) == true { + if mini_func.IsNumberType(ColumnTypeGoPK) == true { Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName) - } else if ColumnTypeGo == "string" { + } else if ColumnTypeGoPK == "string" { Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == \"\"") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != \"\"") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName) - } else if ColumnTypeGo == "uuid.UUID" || ColumnTypeGo == "uuid.NullUUID" { + } else if ColumnTypeGoPK == "uuid.UUID" || ColumnTypeGoPK == "uuid.NullUUID" { Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == uuid.Nil") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != uuid.Nil") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName+".String()") - } else if ColumnTypeGo == "time.Time" { + } else if ColumnTypeGoPK == "time.Time" { Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+".IsZero() == true") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+".IsZero() == false") Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName) } - Otvet = strings.ReplaceAll(Otvet, "m.ID = ", OtvetColumnName+" = ") - Otvet = strings.ReplaceAll(Otvet, " = m.ID", " = "+OtvetColumnName) + //Otvet = strings.ReplaceAll(Otvet, "m.ID = ", OtvetColumnName+" = ") + //Otvet = strings.ReplaceAll(Otvet, " = m.ID", " = "+OtvetColumnName) Otvet = strings.ReplaceAll(Otvet, ", m.ID,", ", "+OtvetColumnName+",") - Otvet = strings.ReplaceAll(Otvet, "(m.ID)", "("+OtvetColumnName+")") + //Otvet = strings.ReplaceAll(Otvet, "(m.ID)", "("+OtvetColumnName+")") + + //Alias преобразуем в int64, и наоборот + if Alias != "" { + Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(m.ID)", ColumnTypeGoPK+"(m."+ColumnNamePK+")") + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(m.ID)", OtvetColumnName) + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", Alias+"("+ColumnNamePK+")") + } else { + Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(m.ID)", "m."+ColumnNamePK+"") + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(m.ID)", OtvetColumnName) + Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", "ID") + } return Otvet } diff --git a/internal/create_files/crud_tables/crud_tables.go b/internal/create_files/crud_tables/crud_tables.go index 4db7176..0237aeb 100644 --- a/internal/create_files/crud_tables/crud_tables.go +++ b/internal/create_files/crud_tables/crud_tables.go @@ -172,6 +172,9 @@ func CreateFiles(Table1 *types.Table) error { //uuid TextDB = create_files.CheckAndAddImportUUID_FromText(TextDB) + //alias + TextDB = create_files.CheckAndAddImportAlias(TextDB) + //удаление пустого импорта TextDB = create_files.DeleteEmptyImport(TextDB) 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 b79034b..3f112c2 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -242,9 +242,6 @@ func CreateFilesTest(Table1 *types.Table) error { } TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1) - // замена ID на PrimaryKey - TextGRPCClient = create_files.ReplacePrimaryKeyOtvetID(TextGRPCClient, Table1) - //SkipNow() TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1) @@ -603,6 +600,9 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) + //ConstantsURL := create_files.FindConstantsURL() + //TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ConstantsURL) + //TextGRPC_Client = create_files.ConvertRequestIdToAlias(TextGRPC_Client, Table1) TextGRPC_Client = create_files.ReplacePrimaryKeyOtvetID(TextGRPC_Client, Table1)