1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал func Getenv()

This commit is contained in:
Nikitin Aleksandr 2024-02-20 12:44:29 +03:00
parent be039bb6b7
commit b57d354faf
3 changed files with 21 additions and 28 deletions

View File

@ -21,7 +21,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
//ID не должен быть =0 //ID не должен быть =0
if m.ID == 0 { if m.ID == 0 {
err = errors.New("Read() error: ID=0") err = errors.New(m.TableNameDB()+" Read() error: ID=0")
return err return err
} }
@ -40,7 +40,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
err = tx.Error err = tx.Error
if err != nil { 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 return err

View File

@ -49,7 +49,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
tx := db.First(m, id) tx := db.First(m, id)
err = tx.Error err = tx.Error
if err != nil { 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 return err
@ -148,12 +148,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
// проверка ID // проверка ID
if is_create == true { if is_create == true {
if int64(m.ID) != 0 { 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) err = errors.New(TextError)
return err return err
} }
} else if int64(m.ID) == 0 { } 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) err = errors.New(TextError)
return err 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) tx = db.Model(&m).Updates(MapOmit)
err = tx.Error err = tx.Error
if err != nil { if err != nil {
TextError := fmt.Sprint("Updates() ", TableName, " id: ", m.ID, " error: ", err) err = fmt.Errorf(m.TableNameDB()+" Create_Update() id: %v, error: %v", m.ID, err)
err = errors.New(TextError)
return err
}
if err != nil {
err = fmt.Errorf("Create_Update() id: %v, error: %v", m.ID, err)
} }
return 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) err = crud.Save_ctx(ctx, &m2)
if err != nil { 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 return err
@ -246,7 +241,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro
var err error var err error
if m.ExtID == 0 { if m.ExtID == 0 {
err = errors.New("Error: ext_id =0") err = errors.New(m.TableNameDB()+" error: ext_id =0")
return err 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) tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m)
err = tx.Error err = tx.Error
if err != nil { 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 return err
@ -314,6 +309,9 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws
tx := db.Delete(m) tx := db.Delete(m)
err = tx.Error err = tx.Error
if err != nil {
err = fmt.Errorf(m.TableNameDB()+" Delete() id: %v, error: %v", m.ID, err)
}
return err return err
} }

View File

@ -49,7 +49,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
tx := db.First(m, id) tx := db.First(m, id)
err = tx.Error err = tx.Error
if err != nil { 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 return err
@ -148,12 +148,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
// проверка ID // проверка ID
if is_create == true { if is_create == true {
if int64(m.ID) != 0 { 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) err = errors.New(TextError)
return err return err
} }
} else if int64(m.ID) == 0 { } 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) err = errors.New(TextError)
return err 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) tx = db.Model(&m).Updates(MapOmit)
err = tx.Error err = tx.Error
if err != nil { if err != nil {
TextError := fmt.Sprint("Updates() ", TableName, " id: ", m.ID, " error: ", err) err = fmt.Errorf(m.TableNameDB()+" Create_Update() id: %v, error: %v", m.ID, err)
err = errors.New(TextError)
return err
}
if err != nil {
err = fmt.Errorf("Create_Update() id: %v, error: %v", m.ID, err)
} }
return 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) err = crud.Save_ctx(ctx, &m2)
if err != nil { 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 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) err = crud.Save_ctx(ctx, &m2)
if err != nil { 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 return err
@ -285,7 +280,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro
var err error var err error
if m.ExtID == 0 { if m.ExtID == 0 {
err = errors.New("Error: ext_id =0") err = errors.New(m.TableNameDB()+" Find_ByExtID() error: ext_id =0")
return err return err
} }
@ -309,7 +304,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type
} }
if m.ExtID == 0 { if m.ExtID == 0 {
err = errors.New("Error: ExtID=0") err = errors.New(m.TableNameDB()+" Find_ByExtID() error: ExtID=0")
return err 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) tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m)
err = tx.Error err = tx.Error
if err != nil { 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 return err