mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-03 01:22:21 +02:00
сделал db
This commit is contained in:
parent
c0fee0933a
commit
3fff82129c
@ -20,7 +20,7 @@ type Crud_DB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read - находит запись в БД по ID
|
// Read - находит запись в БД по ID
|
||||||
func (crud Crud_DB) Read(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Read(m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -29,77 +29,77 @@ func (crud Crud_DB) Read(l *model.LawsuitStatusType) error {
|
|||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err = crud.Read_ctx(ctx, l)
|
err = crud.Read_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read_ctx - находит запись в БД по ID
|
// Read_ctx - находит запись в БД по ID
|
||||||
func (crud Crud_DB) Read_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Read_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
id := l.ID
|
id := m.ID
|
||||||
|
|
||||||
db := postgres_gorm.GetConnection()
|
db := postgres_gorm.GetConnection()
|
||||||
db.WithContext(ctx)
|
db.WithContext(ctx)
|
||||||
|
|
||||||
tx := db.First(l, id)
|
tx := db.First(m, id)
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save - записывает новый или существующий объект в базу данных
|
// Save - записывает новый или существующий объект в базу данных
|
||||||
func (crud Crud_DB) Save(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Save(m *model.LawsuitStatusType) error {
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err := crud.Save_ctx(ctx, l)
|
err := crud.Save_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save_ctx - записывает новый или существующий объект в базу данных
|
// Save_ctx - записывает новый или существующий объект в базу данных
|
||||||
func (crud Crud_DB) Save_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Save_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
is_create := !micro.BoolFromInt64(l.ID)
|
is_create := !micro.BoolFromInt64(m.ID)
|
||||||
err := crud.create_update_ctx(ctx, l, is_create)
|
err := crud.create_update_ctx(ctx, m, is_create)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update - записывает существующий объект в базу данных
|
// Update - записывает существующий объект в базу данных
|
||||||
func (crud Crud_DB) Update(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Update(m *model.LawsuitStatusType) error {
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err := crud.Update_ctx(ctx, l)
|
err := crud.Update_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update_ctx - записывает существующий объект в базу данных
|
// Update_ctx - записывает существующий объект в базу данных
|
||||||
func (crud Crud_DB) Update_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Update_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
err := crud.create_update_ctx(ctx, l, false)
|
err := crud.create_update_ctx(ctx, m, false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create - записывает новый объект в базу данных
|
// Create - записывает новый объект в базу данных
|
||||||
func (crud Crud_DB) Create(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Create(m *model.LawsuitStatusType) error {
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err := crud.Create_ctx(ctx, l)
|
err := crud.Create_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create_ctx - записывает новый объект в базу данных
|
// Create_ctx - записывает новый объект в базу данных
|
||||||
func (crud Crud_DB) Create_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Create_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
err := crud.create_update_ctx(ctx, l, true)
|
err := crud.create_update_ctx(ctx, m, true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_update - записывает объект в базу данных
|
// create_update - записывает объект в базу данных
|
||||||
func (crud Crud_DB) create_update(l *model.LawsuitStatusType, is_create bool) error {
|
func (crud Crud_DB) create_update(m *model.LawsuitStatusType, is_create bool) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
//log.Trace("start Save() ", TableName, " id: ", m.ID)
|
//log.Trace("start Save() ", TableName, " id: ", m.ID)
|
||||||
@ -108,25 +108,25 @@ func (crud Crud_DB) create_update(l *model.LawsuitStatusType, is_create bool) er
|
|||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err = crud.create_update_ctx(ctx, l, is_create)
|
err = crud.create_update_ctx(ctx, m, is_create)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_update_ctx - записывает объект в базу данных
|
// create_update_ctx - записывает объект в базу данных
|
||||||
func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatusType, is_create bool) error {
|
func (crud Crud_DB) create_update_ctx(ctx context.Context, m *model.LawsuitStatusType, is_create bool) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
//log.Trace("start Save() ", TableName, " id: ", m.ID)
|
//log.Trace("start Save() ", TableName, " id: ", m.ID)
|
||||||
|
|
||||||
// проверка ID
|
// проверка ID
|
||||||
if is_create == true {
|
if is_create == true {
|
||||||
if l.ID != 0 {
|
if m.ID != 0 {
|
||||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
||||||
//log.Panic(sError)
|
//log.Panic(sError)
|
||||||
err = errors.New(TextError)
|
err = errors.New(TextError)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if l.ID == 0 {
|
} else if m.ID == 0 {
|
||||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
||||||
err = errors.New(TextError)
|
err = errors.New(TextError)
|
||||||
//log.Panic(sError)
|
//log.Panic(sError)
|
||||||
@ -139,11 +139,11 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
|||||||
|
|
||||||
//заполним даты
|
//заполним даты
|
||||||
Now := time.Now()
|
Now := time.Now()
|
||||||
l.ModifiedAt = Now
|
m.ModifiedAt = Now
|
||||||
if l.IsDeleted == true && l.DeletedAt.IsZero() == true {
|
if m.IsDeleted == true && m.DeletedAt.IsZero() == true {
|
||||||
l.DeletedAt = Now
|
m.DeletedAt = Now
|
||||||
} else if l.IsDeleted == false && l.DeletedAt.IsZero() == false {
|
} else if m.IsDeleted == false && m.DeletedAt.IsZero() == false {
|
||||||
l.DeletedAt = time.Time{}
|
m.DeletedAt = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//колонки с null
|
//колонки с null
|
||||||
@ -152,12 +152,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
|||||||
var ColumnName string
|
var ColumnName string
|
||||||
|
|
||||||
ColumnName = "DeletedAt"
|
ColumnName = "DeletedAt"
|
||||||
if l.DeletedAt.IsZero() == true {
|
if m.DeletedAt.IsZero() == true {
|
||||||
MassOmit = append(MassOmit, ColumnName)
|
MassOmit = append(MassOmit, ColumnName)
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnName = "ExtID"
|
ColumnName = "ExtID"
|
||||||
if l.ExtID == 0 {
|
if m.ExtID == 0 {
|
||||||
MassOmit = append(MassOmit, ColumnName)
|
MassOmit = append(MassOmit, ColumnName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,9 +166,9 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
|||||||
|
|
||||||
//запись
|
//запись
|
||||||
if is_create == true {
|
if is_create == true {
|
||||||
tx = tx.Create(&l)
|
tx = tx.Create(&m)
|
||||||
} else {
|
} else {
|
||||||
tx = tx.Save(&l)
|
tx = tx.Save(&m)
|
||||||
}
|
}
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -178,11 +178,11 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
|||||||
//запишем NULL в пустые колонки
|
//запишем NULL в пустые колонки
|
||||||
for f := 0; f < len(MassOmit); f++ {
|
for f := 0; f < len(MassOmit); f++ {
|
||||||
ColumnName := MassOmit[f]
|
ColumnName := MassOmit[f]
|
||||||
tx = db.Model(&l).Update(ColumnName, gorm.Expr("NULL"))
|
tx = db.Model(&m).Update(ColumnName, gorm.Expr("NULL"))
|
||||||
|
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TextError := fmt.Sprint("db.Update() ", TableName, " id: ", l.ID, " error: ", err)
|
TextError := fmt.Sprint("db.Update() ", TableName, " id: ", m.ID, " error: ", err)
|
||||||
err = errors.New(TextError)
|
err = errors.New(TextError)
|
||||||
return err
|
return err
|
||||||
//log.Panic(sError)
|
//log.Panic(sError)
|
||||||
@ -193,7 +193,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete - записывает is_deleted = true
|
// Delete - записывает is_deleted = true
|
||||||
func (crud Crud_DB) Delete(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Delete(m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -201,32 +201,32 @@ func (crud Crud_DB) Delete(l *model.LawsuitStatusType) error {
|
|||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err = crud.Delete_ctx(ctx, l)
|
err = crud.Delete_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete_ctx - записывает is_deleted = true
|
// Delete_ctx - записывает is_deleted = true
|
||||||
func (crud Crud_DB) Delete_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Delete_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
l2 := model.LawsuitStatusType{}
|
m2 := model.LawsuitStatusType{}
|
||||||
l2.ID = l.ID
|
m2.ID = m.ID
|
||||||
err = crud.Read_ctx(ctx, &l2)
|
err = crud.Read_ctx(ctx, &m2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l2.IsDeleted = true
|
m2.IsDeleted = true
|
||||||
l.IsDeleted = true
|
m.IsDeleted = true
|
||||||
|
|
||||||
err = crud.Save_ctx(ctx, &l2)
|
err = crud.Save_ctx(ctx, &m2)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore - записывает is_deleted = true
|
// Restore - записывает is_deleted = true
|
||||||
func (crud Crud_DB) Restore(l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Restore(m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -234,26 +234,26 @@ func (crud Crud_DB) Restore(l *model.LawsuitStatusType) error {
|
|||||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||||
defer ctxCancelFunc()
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
err = crud.Restore_ctx(ctx, l)
|
err = crud.Restore_ctx(ctx, m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore_ctx - записывает is_deleted = true
|
// Restore_ctx - записывает is_deleted = true
|
||||||
func (crud Crud_DB) Restore_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
func (crud Crud_DB) Restore_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||||
//var Otvet model.LawsuitStatusType
|
//var Otvet model.LawsuitStatusType
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
l2 := model.LawsuitStatusType{}
|
m2 := model.LawsuitStatusType{}
|
||||||
l2.ID = l.ID
|
m2.ID = m.ID
|
||||||
err = crud.Read_ctx(ctx, &l2)
|
err = crud.Read_ctx(ctx, &m2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l2.IsDeleted = false
|
m2.IsDeleted = false
|
||||||
l.IsDeleted = false
|
m.IsDeleted = false
|
||||||
|
|
||||||
err = crud.Save_ctx(ctx, &l2)
|
err = crud.Save_ctx(ctx, &m2)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package db
|
|||||||
import (
|
import (
|
||||||
"github.com/ManyakRus/crud_generator/internal/config"
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
"github.com/ManyakRus/crud_generator/internal/constants"
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/model"
|
|
||||||
"github.com/ManyakRus/crud_generator/internal/types"
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
"github.com/ManyakRus/starter/log"
|
"github.com/ManyakRus/starter/log"
|
||||||
"github.com/ManyakRus/starter/micro"
|
"github.com/ManyakRus/starter/micro"
|
||||||
@ -72,12 +71,13 @@ func CreateDBFiles1(Table1 *types.Table) error {
|
|||||||
TextDB = constants.TEXT_GENERATED + TextDB
|
TextDB = constants.TEXT_GENERATED + TextDB
|
||||||
|
|
||||||
if config.Settings.HAS_IS_DELETED == true {
|
if config.Settings.HAS_IS_DELETED == true {
|
||||||
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncDelete(TextDB, Table1)
|
||||||
TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncDeleteCtx(TextDB, Table1)
|
||||||
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncRestore(TextDB, Table1)
|
||||||
TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncRestoreCtx(TextDB, Table1)
|
||||||
}
|
}
|
||||||
TextDB = model.DeleteFuncFind_byExtID(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncFind_byExtID(TextDB, Table1)
|
||||||
|
TextDB = AddTextOmit(TextDB, Table1)
|
||||||
|
|
||||||
//запись файла
|
//запись файла
|
||||||
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
||||||
@ -123,12 +123,12 @@ func CreateDBTestFiles1(Table1 *types.Table) error {
|
|||||||
TextDB = constants.TEXT_GENERATED + TextDB
|
TextDB = constants.TEXT_GENERATED + TextDB
|
||||||
|
|
||||||
if config.Settings.HAS_IS_DELETED == true {
|
if config.Settings.HAS_IS_DELETED == true {
|
||||||
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncDelete(TextDB, Table1)
|
||||||
TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncDeleteCtx(TextDB, Table1)
|
||||||
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncRestore(TextDB, Table1)
|
||||||
TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncRestoreCtx(TextDB, Table1)
|
||||||
}
|
}
|
||||||
TextDB = model.DeleteFuncFind_byExtID(TextDB, ModelName, Table1)
|
TextDB = DeleteFuncFind_byExtID(TextDB, Table1)
|
||||||
|
|
||||||
//запись файла
|
//запись файла
|
||||||
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
||||||
@ -137,8 +137,8 @@ func CreateDBTestFiles1(Table1 *types.Table) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncDelete - удаляет функцию Delete()
|
// DeleteFuncDelete - удаляет функцию Delete()
|
||||||
func DeleteFuncDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
func DeleteFuncDelete(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -163,8 +163,8 @@ func DeleteFuncDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncRestore - удаляет функцию Restore()
|
// DeleteFuncRestore - удаляет функцию Restore()
|
||||||
func DeleteFuncRestore(TextModel, Modelname string, Table1 *types.Table) string {
|
func DeleteFuncRestore(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -189,8 +189,8 @@ func DeleteFuncRestore(TextModel, Modelname string, Table1 *types.Table) string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncDeleteCtx - удаляет функцию Delete_ctx()
|
// DeleteFuncDeleteCtx - удаляет функцию Delete_ctx()
|
||||||
func DeleteFuncDeleteCtx(TextModel, ModelName string, Table1 *types.Table) string {
|
func DeleteFuncDeleteCtx(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -215,8 +215,8 @@ func DeleteFuncDeleteCtx(TextModel, ModelName string, Table1 *types.Table) strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncRestoreCtx - удаляет функцию Restore_ctx()
|
// DeleteFuncRestoreCtx - удаляет функцию Restore_ctx()
|
||||||
func DeleteFuncRestoreCtx(TextModel, Modelname string, Table1 *types.Table) string {
|
func DeleteFuncRestoreCtx(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -241,8 +241,8 @@ func DeleteFuncRestoreCtx(TextModel, Modelname string, Table1 *types.Table) stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||||
func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) string {
|
func DeleteFuncFind_byExtID(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
//
|
//
|
||||||
_, ok := Table1.MapColumns["ext_id"]
|
_, ok := Table1.MapColumns["ext_id"]
|
||||||
@ -274,8 +274,8 @@ func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncTestDelete - удаляет функцию Delete()
|
// DeleteFuncTestDelete - удаляет функцию Delete()
|
||||||
func DeleteFuncTestDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
func DeleteFuncTestDelete(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -300,8 +300,8 @@ func DeleteFuncTestDelete(TextModel, ModelName string, Table1 *types.Table) stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncTestRestore - удаляет функцию Restore()
|
// DeleteFuncTestRestore - удаляет функцию Restore()
|
||||||
func DeleteFuncTestRestore(TextModel, Modelname string, Table1 *types.Table) string {
|
func DeleteFuncTestRestore(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
_, ok := Table1.MapColumns["is_deleted"]
|
_, ok := Table1.MapColumns["is_deleted"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@ -326,8 +326,8 @@ func DeleteFuncTestRestore(TextModel, Modelname string, Table1 *types.Table) str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||||
func DeleteFuncTestFind_byExtID(TextModel, Modelname string, Table1 *types.Table) string {
|
func DeleteFuncTestFind_byExtID(TextDB string, Table1 *types.Table) string {
|
||||||
Otvet := TextModel
|
Otvet := TextDB
|
||||||
|
|
||||||
//
|
//
|
||||||
_, ok := Table1.MapColumns["ext_id"]
|
_, ok := Table1.MapColumns["ext_id"]
|
||||||
@ -357,3 +357,39 @@ func DeleteFuncTestFind_byExtID(TextModel, Modelname string, Table1 *types.Table
|
|||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddTextOmit(TextDB string, Table1 *types.Table) string {
|
||||||
|
Otvet := TextDB
|
||||||
|
|
||||||
|
TextFind := "\t//игнор пустых колонок"
|
||||||
|
pos1 := strings.Index(Otvet, TextFind)
|
||||||
|
if pos1 < 0 {
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
TextOmit := ""
|
||||||
|
for _, Column1 := range Table1.MapColumns {
|
||||||
|
TypeGo := Column1.TypeGo
|
||||||
|
if TypeGo != "time.Time" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnNameGo := Column1.NameGo
|
||||||
|
TextFind := `if m.` + ColumnNameGo + `.IsZero() == true {`
|
||||||
|
pos1 := strings.Index(TextDB, TextFind)
|
||||||
|
if pos1 >= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
TextOmit = TextOmit + "\t" + `ColumnName = "` + ColumnNameGo + `"
|
||||||
|
if m.` + ColumnNameGo + `.IsZero() == true {
|
||||||
|
MassOmit = append(MassOmit, ColumnName)
|
||||||
|
}
|
||||||
|
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = Otvet[:pos1] + TextOmit + Otvet[pos1:]
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
@ -106,6 +106,7 @@ type ` + ModelName + ` struct {
|
|||||||
Column1, _ := Table1.MapColumns[key1]
|
Column1, _ := Table1.MapColumns[key1]
|
||||||
TextColumn := FindTextColumn(&Column1)
|
TextColumn := FindTextColumn(&Column1)
|
||||||
Otvet = Otvet + TextColumn + "\n"
|
Otvet = Otvet + TextColumn + "\n"
|
||||||
|
Table1.MapColumns[key1] = Column1
|
||||||
}
|
}
|
||||||
|
|
||||||
Otvet = Otvet + "\n}"
|
Otvet = Otvet + "\n}"
|
||||||
@ -124,6 +125,7 @@ func FindTextColumn(Column1 *types.Column) string {
|
|||||||
log.Panic("GetMappings() ", Column1.Type, " error: not found")
|
log.Panic("GetMappings() ", Column1.Type, " error: not found")
|
||||||
}
|
}
|
||||||
Type_go := SQLMapping1.GoType
|
Type_go := SQLMapping1.GoType
|
||||||
|
Column1.TypeGo = Type_go
|
||||||
TextDefaultValue := FindTextDefaultValue(Type_go)
|
TextDefaultValue := FindTextDefaultValue(Type_go)
|
||||||
TextPrimaryKey := FindTextPrimaryKey(Column1.Is_identity)
|
TextPrimaryKey := FindTextPrimaryKey(Column1.Is_identity)
|
||||||
Description := Column1.Description
|
Description := Column1.Description
|
||||||
|
@ -51,37 +51,8 @@ func CreateAllFolders() {
|
|||||||
|
|
||||||
//
|
//
|
||||||
Filename := dir + config.Settings.SERVICE_NAME
|
Filename := dir + config.Settings.SERVICE_NAME
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err := micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal"
|
|
||||||
err = CreateFolder(Filename, 0777)
|
|
||||||
if err != nil {
|
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
|
||||||
}
|
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg"
|
|
||||||
err = CreateFolder(Filename, 0777)
|
|
||||||
if err != nil {
|
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
|
||||||
}
|
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model"
|
|
||||||
err = CreateFolder(Filename, 0777)
|
|
||||||
if err != nil {
|
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
|
||||||
}
|
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
if config.Settings.NEED_CRUD == true {
|
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
|
|
||||||
err = CreateFolder(Filename, 0777)
|
err = CreateFolder(Filename, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
@ -89,72 +60,139 @@ func CreateAllFolders() {
|
|||||||
log.Info("CreateFolder() ", Filename)
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal"
|
||||||
|
ok, err = micro.FileExists(Filename)
|
||||||
|
if ok == false || err != nil {
|
||||||
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg"
|
||||||
|
ok, err = micro.FileExists(Filename)
|
||||||
|
if ok == false || err != nil {
|
||||||
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
|
}
|
||||||
|
//
|
||||||
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model"
|
||||||
|
ok, err = micro.FileExists(Filename)
|
||||||
|
if ok == false || err != nil {
|
||||||
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
|
}
|
||||||
|
if config.Settings.NEED_CRUD == true {
|
||||||
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
|
||||||
|
ok, err = micro.FileExists(Filename)
|
||||||
|
if ok == false || err != nil {
|
||||||
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if config.Settings.NEED_GRPC == true {
|
if config.Settings.NEED_GRPC == true {
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_server"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_server"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_client"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_client"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Settings.NEED_NRPC == true {
|
if config.Settings.NEED_NRPC == true {
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_server"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_server"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_client"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_client"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
||||||
err = CreateFolder(Filename, 0777)
|
ok, err = micro.FileExists(Filename)
|
||||||
if err != nil {
|
if ok == false || err != nil {
|
||||||
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//return err
|
//return err
|
||||||
|
@ -9,6 +9,7 @@ type Column struct {
|
|||||||
TableKey string `json:"table_key" gorm:"column:table_key;default:''"`
|
TableKey string `json:"table_key" gorm:"column:table_key;default:''"`
|
||||||
ColumnKey string `json:"column_key" gorm:"column:column_key;default:''"`
|
ColumnKey string `json:"column_key" gorm:"column:column_key;default:''"`
|
||||||
NameGo string `gorm:-`
|
NameGo string `gorm:-`
|
||||||
|
TypeGo string `gorm:-`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Table struct {
|
type Table struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user