From b57d354fafeb7c73c0718ac0ff7de6e73c039e4e Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 20 Feb 2024 12:44:29 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20func=20G?= =?UTF-8?q?etenv()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/db/crud/crud_table_update_func.go_ | 4 ++-- bin/templates/pkg/db/crud/crud_tables.go_ | 22 ++++++++---------- .../pkg/db/crud/crud_tables_rapira.go_ | 23 ++++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) 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 c660965..6d24a86 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_func.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_func.go_ @@ -21,7 +21,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui //ID не должен быть =0 if m.ID == 0 { - err = errors.New("Read() error: ID=0") + err = errors.New(m.TableNameDB()+" Read() error: ID=0") return err } @@ -40,7 +40,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui err = tx.Error if err != nil { - err = fmt.Errorf("Read() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", m.ID, err) } return err diff --git a/bin/templates/pkg/db/crud/crud_tables.go_ b/bin/templates/pkg/db/crud/crud_tables.go_ index 68b1b70..3a8d5c6 100644 --- a/bin/templates/pkg/db/crud/crud_tables.go_ +++ b/bin/templates/pkg/db/crud/crud_tables.go_ @@ -49,7 +49,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui tx := db.First(m, id) err = tx.Error if err != nil { - err = fmt.Errorf("Read() id: %v, error: %v", id, err) + err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", id, err) } return err @@ -148,12 +148,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ // проверка ID if is_create == true { if int64(m.ID) != 0 { - TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0") + TextError := fmt.Sprint(m.TableNameDB()+" Save() ", TableName, " error: id !=0") err = errors.New(TextError) return err } } else if int64(m.ID) == 0 { - TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0") + TextError := fmt.Sprint(m.TableNameDB()+" Save() ", TableName, " error: id =0") err = errors.New(TextError) return err } @@ -191,12 +191,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ tx = db.Model(&m).Updates(MapOmit) err = tx.Error if err != nil { - TextError := fmt.Sprint("Updates() ", TableName, " id: ", m.ID, " error: ", err) - err = errors.New(TextError) - return err - } - if err != nil { - err = fmt.Errorf("Create_Update() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Create_Update() id: %v, error: %v", m.ID, err) } return err @@ -235,7 +230,7 @@ func (crud Crud_DB) Restore_ctx(ctx context.Context, m *lawsuit_status_types.Law err = crud.Save_ctx(ctx, &m2) if err != nil { - err = fmt.Errorf("Restore() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Restore() id: %v, error: %v", m.ID, err) } return err @@ -246,7 +241,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro var err error if m.ExtID == 0 { - err = errors.New("Error: ext_id =0") + err = errors.New(m.TableNameDB()+" error: ext_id =0") return err } @@ -280,7 +275,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m) err = tx.Error if err != nil { - err = fmt.Errorf("Find_ByExtID() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Find_ByExtID() id: %v, error: %v", m.ID, err) } return err @@ -314,6 +309,9 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws tx := db.Delete(m) err = tx.Error + if err != nil { + err = fmt.Errorf(m.TableNameDB()+" Delete() id: %v, error: %v", m.ID, err) + } return err } diff --git a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ index 232875f..97ee672 100644 --- a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ @@ -49,7 +49,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui tx := db.First(m, id) err = tx.Error if err != nil { - err = fmt.Errorf("Read() id: %v, error: %v", id, err) + err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", id, err) } return err @@ -148,12 +148,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ // проверка ID if is_create == true { if int64(m.ID) != 0 { - TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0") + TextError := fmt.Sprint(m.TableNameDB()+" Save() ", TableName, " error: id !=0") err = errors.New(TextError) return err } } else if int64(m.ID) == 0 { - TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0") + TextError := fmt.Sprint(m.TableNameDB()+" Save() ", TableName, " error: id =0") err = errors.New(TextError) return err } @@ -191,12 +191,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ tx = db.Model(&m).Updates(MapOmit) err = tx.Error if err != nil { - TextError := fmt.Sprint("Updates() ", TableName, " id: ", m.ID, " error: ", err) - err = errors.New(TextError) - return err - } - if err != nil { - err = fmt.Errorf("Create_Update() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Create_Update() id: %v, error: %v", m.ID, err) } return err @@ -235,7 +230,7 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws err = crud.Save_ctx(ctx, &m2) if err != nil { - err = fmt.Errorf("Delete() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Delete() id: %v, error: %v", m.ID, err) } return err @@ -274,7 +269,7 @@ func (crud Crud_DB) Restore_ctx(ctx context.Context, m *lawsuit_status_types.Law err = crud.Save_ctx(ctx, &m2) if err != nil { - err = fmt.Errorf("Restore() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Restore() id: %v, error: %v", m.ID, err) } return err @@ -285,7 +280,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro var err error if m.ExtID == 0 { - err = errors.New("Error: ext_id =0") + err = errors.New(m.TableNameDB()+" Find_ByExtID() error: ext_id =0") return err } @@ -309,7 +304,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type } if m.ExtID == 0 { - err = errors.New("Error: ExtID=0") + err = errors.New(m.TableNameDB()+" Find_ByExtID() error: ExtID=0") return err } @@ -319,7 +314,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m) err = tx.Error if err != nil { - err = fmt.Errorf("Find_ByExtID() id: %v, error: %v", m.ID, err) + err = fmt.Errorf(m.TableNameDB()+" Find_ByExtID() id: %v, error: %v", m.ID, err) } return err