1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-04 13:23:00 +02:00

сделал uuid

This commit is contained in:
Nikitin Aleksandr 2024-05-02 15:39:32 +03:00
parent b5f37b5b3b
commit f069ab8314
8 changed files with 70 additions and 183 deletions

View File

@ -51,6 +51,6 @@ conn:
image_connections ./internal docs/connections.graphml $(SERVICENAME)
lines:
clear
go_lines_count ./ ./docs/lines_count.txt 5
go_lines_count ./ ./docs/lines_count.txt 2
licenses:
golicense -out-xlsx=./docs/licenses.xlsx $(FILEAPP)

View File

@ -10,6 +10,6 @@ const TIMEOUT_DB_SECONDS = 30
const TEXT_RECORD_NOT_FOUND = "record not found"
const TextCrudIsNotInit = "Need initializate crud with InitCrudTransport_NRPC() function at first."
const TextCrudIsNotInit = "Need initializate crud with InitCrudTransport_GRPC() function at first."
var ErrorCrudIsNotInit error = errors.New(TextCrudIsNotInit)

View File

@ -34,7 +34,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
//
var tx *gorm.DB
Value := m.ColumnName
if 0==1 && Value == 0 {
if Value == 0 {
tx = db.Model(&m).Update("ColumnName", gorm.Expr("NULL"))
} else {
tx = db.Model(&m).Update("ColumnName", Value)

View File

@ -77,8 +77,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
return err
}
is_create := micro.IsEmptyValue(int64(m.ID))
err = create_update_ctx(ctx, db, m, is_create, nil)
err = create_update_ctx(ctx, db, m, nil)
return err
}
@ -102,7 +101,14 @@ func Update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui
return err
}
err = create_update_ctx(ctx, db, m, false, nil)
// проверка ID
if int64(m.ID) == 0 {
TextError := fmt.Sprint(m.TableNameDB()+" Update() ", TableName, " error: id =0")
err = errors.New(TextError)
return err
}
err = create_update_ctx(ctx, db, m, nil)
return err
}
@ -126,12 +132,19 @@ func Create_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui
return err
}
err = create_update_ctx(ctx, db, m, true, nil)
// проверка ID
if int64(m.ID) != 0 {
TextError := fmt.Sprint(m.TableNameDB()+" Save() ", TableName, " error: id !=0")
err = errors.New(TextError)
return err
}
err = create_update_ctx(ctx, db, m, nil)
return err
}
// create_update - записывает объект в базу данных
func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType, is_create bool) error {
func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType) error {
var err error
ctxMain := contextmain.GetContext()
@ -140,12 +153,12 @@ func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType, is_
db := postgres_gorm.GetConnection()
err = create_update_ctx(ctx, db, m, is_create, nil)
err = create_update_ctx(ctx, db, m, nil)
return err
}
// create_update_ctx - записывает объект в базу данных
func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitStatusType, is_create bool, MassNeedUpdateFields []string) error {
func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitStatusType, MassNeedUpdateFields []string) error {
var err error
// log.Trace("start Save() ", TableName, " id: ", int64(m.ID))
@ -155,20 +168,6 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
return err
}
// проверка ID
if is_create == true {
if int64(m.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(m.TableNameDB()+" Save() ", TableName, " error: id =0")
err = errors.New(TextError)
return err
}
// заполним даты
//Text_modified_at
//Text_is_deleted_deleted_at
//Text_created_at
@ -190,11 +189,7 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
tx = tx.Omit(MassOmit...)
// запись
if is_create == true {
tx = tx.Create(&m)
} else {
tx = tx.Save(&m)
}
tx = tx.Create(&m)
err = tx.Error
if err != nil {
return err

View File

@ -77,8 +77,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
return err
}
is_create := micro.IsEmptyValue(int64(m.ID))
err = create_update_ctx(ctx, db, m, is_create, nil)
err = create_update_ctx(ctx, db, m, nil)
return err
}
@ -102,7 +101,14 @@ func Update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui
return err
}
err = create_update_ctx(ctx, db, m, false, nil)
// проверка ID
if int64(m.ID) == 0 {
TextError := fmt.Sprint(m.TableNameDB()+" Update() ", TableName, " error: id =0")
err = errors.New(TextError)
return err
}
err = create_update_ctx(ctx, db, m, nil)
return err
}
@ -126,12 +132,19 @@ func Create_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui
return err
}
err = create_update_ctx(ctx, db, m, true, nil)
// проверка ID
if int64(m.ID) != 0 {
TextError := fmt.Sprint(m.TableNameDB()+" Create() ", TableName, " error: id !=0")
err = errors.New(TextError)
return err
}
err = create_update_ctx(ctx, db, m, nil)
return err
}
// create_update - записывает объект в базу данных
func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType, is_create bool) error {
func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType) error {
var err error
ctxMain := contextmain.GetContext()
@ -140,12 +153,12 @@ func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType, is_
db := postgres_gorm.GetConnection()
err = create_update_ctx(ctx, db, m, is_create, nil)
err = create_update_ctx(ctx, db, m, nil)
return err
}
// create_update_ctx - записывает объект в базу данных
func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitStatusType, is_create bool, MassNeedUpdateFields []string) error {
func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitStatusType, MassNeedUpdateFields []string) error {
var err error
// log.Trace("start Save() ", TableName, " id: ", int64(m.ID))
@ -155,20 +168,6 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
return err
}
// проверка ID
if is_create == true {
if int64(m.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(m.TableNameDB()+" Save() ", TableName, " error: id =0")
err = errors.New(TextError)
return err
}
// заполним даты
//Text_modified_at
//Text_is_deleted_deleted_at
//Text_created_at
@ -190,11 +189,7 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
tx = tx.Omit(MassOmit...)
// запись
if is_create == true {
tx = tx.Create(&m)
} else {
tx = tx.Save(&m)
}
tx = tx.Create(&m)
err = tx.Error
if err != nil {
return err

View File

@ -1 +1,2 @@
//заполним даты
m.ModifiedAt = time.Now()

View File

@ -1,125 +1,9 @@
Name Level Lines count Functions count
. 1 429466 15859
bin 2 415270 15367
crud_service 3 164652 6481
api 4 30511 1602
grpc_proto 5 30511 1602
bin 4 0 0
cmd 4 29 2
crud_service 5 29 2
docs 4 0 0
internal 4 28377 771
app 5 28377 771
pkg 4 105735 4106
crud_starter 5 2708 150
db 5 30261 1139
network 5 60243 1838
object_model 5 12523 979
scripts 4 0 0
sync_service 3 250435 8876
api 4 0 0
bin 4 0 0
cmd 4 29 2
sync_service 5 29 2
docs 4 0 0
internal 4 73503 1954
app 5 73503 1954
pkg 4 176903 6920
crud_starter 5 2633 150
db 5 79238 2980
network 5 74477 2137
object_model 5 20555 1653
scripts 4 0 0
templates 3 183 10
api 4 0 0
bin 4 0 0
cmd 4 0 0
configs_ 4 0 0
docs 4 0 0
internal 4 14 1
app 5 14 1
pkg 4 169 9
crud_starter 5 15 3
db 5 94 2
network 5 60 4
object_model 5 0 0
scripts 4 0 0
cmd 2 45 3
crud_generator 3 45 3
docs 2 0 0
examples 2 599 26
crud_service 3 163 6
templates 4 163 6
api 5 0 0
bin 5 0 0
cmd 5 0 0
configs_ 5 0 0
docs 5 0 0
internal 5 14 1
pkg 5 149 5
scripts 5 0 0
default 3 218 10
templates 4 218 10
api 5 0 0
bin 5 0 0
cmd 5 0 0
configs_ 5 0 0
docs 5 0 0
internal 5 14 1
pkg 5 204 9
scripts 5 0 0
rapira 3 218 10
templates_main 4 218 10
api 5 0 0
bin 5 0 0
cmd 5 0 0
configs_ 5 0 0
docs 5 0 0
internal 5 14 1
pkg 5 204 9
scripts 5 0 0
rapira_bank 3 0 0
internal 2 9808 316
config 3 553 7
constants 3 64 0
create_files 3 7971 280
alias 4 56 2
crud_starter 4 519 26
crud_starter_tables 4 306 5
db_crud_tables 4 906 16
db_tables 4 427 12
env_file 4 127 3
generation_code_sh 4 67 2
grpc_client 4 175 3
grpc_client_tables 4 825 19
grpc_server_tables 4 768 17
main_file 4 84 2
makefile 4 97 3
model_tables 4 686 21
nrpc_client 4 160 3
nrpc_client_tables 4 316 11
nrpc_server 4 2 0
protobuf 4 433 24
server_grpc_func 4 83 2
server_grpc_starter 4 92 2
server_nrpc_starter 4 93 2
folders 3 280 6
load_configs 3 260 12
logic 3 215 3
mini_func 3 15 1
postgres 3 401 7
types 3 49 0
pkg 2 3744 147
db 3 0 0
dbmeta 3 3460 134
grpc 3 0 0
grpc_client 4 0 0
grpc_proto 4 0 0
grpc_server 4 0 0
nrpc_client 4 0 0
nrpc_server 4 0 0
model 3 0 0
nrpc 3 0 0
utils 3 284 13
scripts 2 0 0
test_copy 3 0 0
Name Level Lines count Functions count
. 1 792417 30025
bin 2 777203 29506
cmd 2 46 3
docs 2 0 0
examples 2 599 26
internal 2 10825 343
pkg 2 3744 147
scripts 2 0 0

View File

@ -627,6 +627,18 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
FuncName := "Update_" + ColumnName
TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1, Column1.TypeGo)
//запись null в nullable колонки
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") {
} else {
TextFind := ` if Value == 0 {
tx = db.Model(&m).Update("ColumnName", gorm.Expr("NULL"))
} else {
tx = db.Model(&m).Update("ColumnName", Value)
}`
TextReplace := ` tx = db.Model(&m).Update("ColumnName", Value)`
Otvet = strings.ReplaceAll(Otvet, TextFind, TextReplace)
}
//заменяем Read_ctx()
Otvet = strings.ReplaceAll(Otvet, " Read_ctx ", " "+FuncName+"_ctx ")
Otvet = strings.ReplaceAll(Otvet, " Read_ctx(", " "+FuncName+"_ctx(")
@ -649,9 +661,9 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
//внешние ключи заменяем 0 на null
TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value")
Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty)
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") {
Otvet = strings.ReplaceAll(Otvet, "0==1 && ", "")
}
//if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") {
// Otvet = strings.ReplaceAll(Otvet, "0==1 && ", "")
//}
return Otvet
}