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
|
||||
func (crud Crud_DB) Read(l *model.LawsuitStatusType) error {
|
||||
func (crud Crud_DB) Read(m *model.LawsuitStatusType) error {
|
||||
//var Otvet model.LawsuitStatusType
|
||||
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))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.Read_ctx(ctx, l)
|
||||
err = crud.Read_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 err error
|
||||
|
||||
id := l.ID
|
||||
id := m.ID
|
||||
|
||||
db := postgres_gorm.GetConnection()
|
||||
db.WithContext(ctx)
|
||||
|
||||
tx := db.First(l, id)
|
||||
tx := db.First(m, id)
|
||||
err = tx.Error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Save - записывает новый или существующий объект в базу данных
|
||||
func (crud Crud_DB) Save(l *model.LawsuitStatusType) error {
|
||||
func (crud Crud_DB) Save(m *model.LawsuitStatusType) error {
|
||||
ctxMain := context.Background()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err := crud.Save_ctx(ctx, l)
|
||||
err := crud.Save_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Save_ctx - записывает новый или существующий объект в базу данных
|
||||
func (crud Crud_DB) Save_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
||||
is_create := !micro.BoolFromInt64(l.ID)
|
||||
err := crud.create_update_ctx(ctx, l, is_create)
|
||||
func (crud Crud_DB) Save_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||
is_create := !micro.BoolFromInt64(m.ID)
|
||||
err := crud.create_update_ctx(ctx, m, is_create)
|
||||
return err
|
||||
}
|
||||
|
||||
// Update - записывает существующий объект в базу данных
|
||||
func (crud Crud_DB) Update(l *model.LawsuitStatusType) error {
|
||||
func (crud Crud_DB) Update(m *model.LawsuitStatusType) error {
|
||||
ctxMain := context.Background()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err := crud.Update_ctx(ctx, l)
|
||||
err := crud.Update_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Update_ctx - записывает существующий объект в базу данных
|
||||
func (crud Crud_DB) Update_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
||||
err := crud.create_update_ctx(ctx, l, false)
|
||||
func (crud Crud_DB) Update_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||
err := crud.create_update_ctx(ctx, m, false)
|
||||
return err
|
||||
}
|
||||
|
||||
// Create - записывает новый объект в базу данных
|
||||
func (crud Crud_DB) Create(l *model.LawsuitStatusType) error {
|
||||
func (crud Crud_DB) Create(m *model.LawsuitStatusType) error {
|
||||
ctxMain := context.Background()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err := crud.Create_ctx(ctx, l)
|
||||
err := crud.Create_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Create_ctx - записывает новый объект в базу данных
|
||||
func (crud Crud_DB) Create_ctx(ctx context.Context, l *model.LawsuitStatusType) error {
|
||||
err := crud.create_update_ctx(ctx, l, true)
|
||||
func (crud Crud_DB) Create_ctx(ctx context.Context, m *model.LawsuitStatusType) error {
|
||||
err := crud.create_update_ctx(ctx, m, true)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
//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))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.create_update_ctx(ctx, l, is_create)
|
||||
err = crud.create_update_ctx(ctx, m, is_create)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
//log.Trace("start Save() ", TableName, " id: ", m.ID)
|
||||
|
||||
// проверка ID
|
||||
if is_create == true {
|
||||
if l.ID != 0 {
|
||||
if m.ID != 0 {
|
||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
||||
//log.Panic(sError)
|
||||
err = errors.New(TextError)
|
||||
return err
|
||||
}
|
||||
} else if l.ID == 0 {
|
||||
} else if m.ID == 0 {
|
||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
||||
err = errors.New(TextError)
|
||||
//log.Panic(sError)
|
||||
@ -139,11 +139,11 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
||||
|
||||
//заполним даты
|
||||
Now := time.Now()
|
||||
l.ModifiedAt = Now
|
||||
if l.IsDeleted == true && l.DeletedAt.IsZero() == true {
|
||||
l.DeletedAt = Now
|
||||
} else if l.IsDeleted == false && l.DeletedAt.IsZero() == false {
|
||||
l.DeletedAt = time.Time{}
|
||||
m.ModifiedAt = Now
|
||||
if m.IsDeleted == true && m.DeletedAt.IsZero() == true {
|
||||
m.DeletedAt = Now
|
||||
} else if m.IsDeleted == false && m.DeletedAt.IsZero() == false {
|
||||
m.DeletedAt = time.Time{}
|
||||
}
|
||||
|
||||
//колонки с null
|
||||
@ -152,12 +152,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
||||
var ColumnName string
|
||||
|
||||
ColumnName = "DeletedAt"
|
||||
if l.DeletedAt.IsZero() == true {
|
||||
if m.DeletedAt.IsZero() == true {
|
||||
MassOmit = append(MassOmit, ColumnName)
|
||||
}
|
||||
|
||||
ColumnName = "ExtID"
|
||||
if l.ExtID == 0 {
|
||||
if m.ExtID == 0 {
|
||||
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 {
|
||||
tx = tx.Create(&l)
|
||||
tx = tx.Create(&m)
|
||||
} else {
|
||||
tx = tx.Save(&l)
|
||||
tx = tx.Save(&m)
|
||||
}
|
||||
err = tx.Error
|
||||
if err != nil {
|
||||
@ -178,11 +178,11 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
||||
//запишем NULL в пустые колонки
|
||||
for f := 0; f < len(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
|
||||
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)
|
||||
return err
|
||||
//log.Panic(sError)
|
||||
@ -193,7 +193,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, l *model.LawsuitStatu
|
||||
}
|
||||
|
||||
// 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 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))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.Delete_ctx(ctx, l)
|
||||
err = crud.Delete_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 err error
|
||||
|
||||
l2 := model.LawsuitStatusType{}
|
||||
l2.ID = l.ID
|
||||
err = crud.Read_ctx(ctx, &l2)
|
||||
m2 := model.LawsuitStatusType{}
|
||||
m2.ID = m.ID
|
||||
err = crud.Read_ctx(ctx, &m2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l2.IsDeleted = true
|
||||
l.IsDeleted = true
|
||||
m2.IsDeleted = true
|
||||
m.IsDeleted = true
|
||||
|
||||
err = crud.Save_ctx(ctx, &l2)
|
||||
err = crud.Save_ctx(ctx, &m2)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 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))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.Restore_ctx(ctx, l)
|
||||
err = crud.Restore_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 err error
|
||||
|
||||
l2 := model.LawsuitStatusType{}
|
||||
l2.ID = l.ID
|
||||
err = crud.Read_ctx(ctx, &l2)
|
||||
m2 := model.LawsuitStatusType{}
|
||||
m2.ID = m.ID
|
||||
err = crud.Read_ctx(ctx, &m2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l2.IsDeleted = false
|
||||
l.IsDeleted = false
|
||||
m2.IsDeleted = false
|
||||
m.IsDeleted = false
|
||||
|
||||
err = crud.Save_ctx(ctx, &l2)
|
||||
err = crud.Save_ctx(ctx, &m2)
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package db
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
"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/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
@ -72,12 +71,13 @@ func CreateDBFiles1(Table1 *types.Table) error {
|
||||
TextDB = constants.TEXT_GENERATED + TextDB
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncDelete(TextDB, Table1)
|
||||
TextDB = DeleteFuncDeleteCtx(TextDB, Table1)
|
||||
TextDB = DeleteFuncRestore(TextDB, 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)
|
||||
@ -123,12 +123,12 @@ func CreateDBTestFiles1(Table1 *types.Table) error {
|
||||
TextDB = constants.TEXT_GENERATED + TextDB
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1)
|
||||
TextDB = DeleteFuncDelete(TextDB, Table1)
|
||||
TextDB = DeleteFuncDeleteCtx(TextDB, Table1)
|
||||
TextDB = DeleteFuncRestore(TextDB, 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)
|
||||
@ -137,8 +137,8 @@ func CreateDBTestFiles1(Table1 *types.Table) error {
|
||||
}
|
||||
|
||||
// DeleteFuncDelete - удаляет функцию Delete()
|
||||
func DeleteFuncDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncDelete(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -163,8 +163,8 @@ func DeleteFuncDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
||||
}
|
||||
|
||||
// DeleteFuncRestore - удаляет функцию Restore()
|
||||
func DeleteFuncRestore(TextModel, Modelname string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncRestore(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -189,8 +189,8 @@ func DeleteFuncRestore(TextModel, Modelname string, Table1 *types.Table) string
|
||||
}
|
||||
|
||||
// DeleteFuncDeleteCtx - удаляет функцию Delete_ctx()
|
||||
func DeleteFuncDeleteCtx(TextModel, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncDeleteCtx(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -215,8 +215,8 @@ func DeleteFuncDeleteCtx(TextModel, ModelName string, Table1 *types.Table) strin
|
||||
}
|
||||
|
||||
// DeleteFuncRestoreCtx - удаляет функцию Restore_ctx()
|
||||
func DeleteFuncRestoreCtx(TextModel, Modelname string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncRestoreCtx(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -241,8 +241,8 @@ func DeleteFuncRestoreCtx(TextModel, Modelname string, Table1 *types.Table) stri
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncFind_byExtID(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
//
|
||||
_, ok := Table1.MapColumns["ext_id"]
|
||||
@ -274,8 +274,8 @@ func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) st
|
||||
}
|
||||
|
||||
// DeleteFuncTestDelete - удаляет функцию Delete()
|
||||
func DeleteFuncTestDelete(TextModel, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncTestDelete(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -300,8 +300,8 @@ func DeleteFuncTestDelete(TextModel, ModelName string, Table1 *types.Table) stri
|
||||
}
|
||||
|
||||
// DeleteFuncTestRestore - удаляет функцию Restore()
|
||||
func DeleteFuncTestRestore(TextModel, Modelname string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncTestRestore(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
@ -326,8 +326,8 @@ func DeleteFuncTestRestore(TextModel, Modelname string, Table1 *types.Table) str
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncTestFind_byExtID(TextModel, Modelname string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
func DeleteFuncTestFind_byExtID(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
//
|
||||
_, ok := Table1.MapColumns["ext_id"]
|
||||
@ -357,3 +357,39 @@ func DeleteFuncTestFind_byExtID(TextModel, Modelname string, Table1 *types.Table
|
||||
|
||||
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]
|
||||
TextColumn := FindTextColumn(&Column1)
|
||||
Otvet = Otvet + TextColumn + "\n"
|
||||
Table1.MapColumns[key1] = Column1
|
||||
}
|
||||
|
||||
Otvet = Otvet + "\n}"
|
||||
@ -124,6 +125,7 @@ func FindTextColumn(Column1 *types.Column) string {
|
||||
log.Panic("GetMappings() ", Column1.Type, " error: not found")
|
||||
}
|
||||
Type_go := SQLMapping1.GoType
|
||||
Column1.TypeGo = Type_go
|
||||
TextDefaultValue := FindTextDefaultValue(Type_go)
|
||||
TextPrimaryKey := FindTextPrimaryKey(Column1.Is_identity)
|
||||
Description := Column1.Description
|
||||
|
@ -51,111 +51,149 @@ func CreateAllFolders() {
|
||||
|
||||
//
|
||||
Filename := dir + config.Settings.SERVICE_NAME
|
||||
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() + "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 {
|
||||
//
|
||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc"
|
||||
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() + "grpc" + micro.SeparatorFile() + "grpc_server"
|
||||
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() + "grpc" + micro.SeparatorFile() + "grpc_client"
|
||||
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() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
||||
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_NRPC == true {
|
||||
//
|
||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc"
|
||||
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() + "grpc" + micro.SeparatorFile() + "nrpc_server"
|
||||
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() + "grpc" + micro.SeparatorFile() + "nrpc_client"
|
||||
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() + "grpc" + micro.SeparatorFile() + "grpc_proto"
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
//return err
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ type Column struct {
|
||||
TableKey string `json:"table_key" gorm:"column:table_key;default:''"`
|
||||
ColumnKey string `json:"column_key" gorm:"column:column_key;default:''"`
|
||||
NameGo string `gorm:-`
|
||||
TypeGo string `gorm:-`
|
||||
}
|
||||
|
||||
type Table struct {
|
||||
|
Loading…
Reference in New Issue
Block a user