mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-06-10 00:17:29 +02:00
сделал constants_
This commit is contained in:
parent
b5fd8053b4
commit
64ca01f693
@ -32,7 +32,7 @@ func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_p
|
|||||||
db := postgres_gorm.GetConnection()
|
db := postgres_gorm.GetConnection()
|
||||||
ID := Request.ID
|
ID := Request.ID
|
||||||
m := &lawsuit_status_types.LawsuitStatusType{}
|
m := &lawsuit_status_types.LawsuitStatusType{}
|
||||||
m.ID = ID
|
m.ID = IntToAlias(ID)
|
||||||
err = crud_lawsuit_status_types.Read_ctx(ctx, db, m)
|
err = crud_lawsuit_status_types.Read_ctx(ctx, db, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Otvet, err
|
return &Otvet, err
|
||||||
@ -71,7 +71,7 @@ func (s *ServerGRPC) LawsuitStatusType_Delete(ctx context.Context, Request *grpc
|
|||||||
db := postgres_gorm.GetConnection()
|
db := postgres_gorm.GetConnection()
|
||||||
ID := Request.ID
|
ID := Request.ID
|
||||||
m := &lawsuit_status_types.LawsuitStatusType{}
|
m := &lawsuit_status_types.LawsuitStatusType{}
|
||||||
m.ID = ID
|
m.ID = IntToAlias(ID)
|
||||||
err = crud_lawsuit_status_types.Delete_ctx(ctx, db, m)
|
err = crud_lawsuit_status_types.Delete_ctx(ctx, db, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Otvet, err
|
return &Otvet, err
|
||||||
@ -110,7 +110,7 @@ func (s *ServerGRPC) LawsuitStatusType_Restore(ctx context.Context, Request *grp
|
|||||||
db := postgres_gorm.GetConnection()
|
db := postgres_gorm.GetConnection()
|
||||||
ID := Request.ID
|
ID := Request.ID
|
||||||
m := &lawsuit_status_types.LawsuitStatusType{}
|
m := &lawsuit_status_types.LawsuitStatusType{}
|
||||||
m.ID = ID
|
m.ID = IntToAlias(ID)
|
||||||
err = crud_lawsuit_status_types.Restore_ctx(ctx, db, m)
|
err = crud_lawsuit_status_types.Restore_ctx(ctx, db, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Otvet, err
|
return &Otvet, err
|
||||||
|
@ -54,7 +54,7 @@ func ReadFromCache_ctx(ctx context.Context, db *gorm.DB, ID int64) (lawsuit_stat
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
||||||
Otvet.ID = ID
|
Otvet.ID = IntToAlias(ID)
|
||||||
err = Read_ctx(ctx, db, &Otvet)
|
err = Read_ctx(ctx, db, &Otvet)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cache.Add(ID, Otvet)
|
cache.Add(ID, Otvet)
|
||||||
|
@ -38,7 +38,7 @@ func UpdateManyFields_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_ty
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(m.ID) == 0 {
|
if IntFromAlias(m.ID) == 0 {
|
||||||
err = errors.New(m.TableNameDB() + " UpdateManyFields() error: ID=0")
|
err = errors.New(m.TableNameDB() + " UpdateManyFields() error: ID=0")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
|||||||
}
|
}
|
||||||
|
|
||||||
//ID не должен быть =0
|
//ID не должен быть =0
|
||||||
if int64(m.ID) == 0 {
|
if IntFromAlias(m.ID) == 0 {
|
||||||
err = errors.New(m.TableNameDB()+" Read() error: ID=0")
|
err = errors.New(m.TableNameDB()+" Read() error: ID=0")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -41,12 +41,12 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
|||||||
}
|
}
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", m.ID, err)
|
err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", IntFromAlias(m.ID), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//удалим из кэша
|
//удалим из кэша
|
||||||
cache.Remove(m.ID)
|
cache.Remove(IntFromAlias(m.ID))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -189,14 +189,14 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
|
|||||||
tx = tx.Omit(MassOmit...)
|
tx = tx.Omit(MassOmit...)
|
||||||
|
|
||||||
// запись
|
// запись
|
||||||
tx = tx.Create(&m)
|
tx = tx.Save(&m)
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//удалим из кэша
|
//удалим из кэша
|
||||||
//cache.Remove(m.ID)
|
//cache.Remove(IntFromAlias(m.ID))
|
||||||
|
|
||||||
//запишем NULL в пустые колонки
|
//запишем NULL в пустые колонки
|
||||||
MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit)
|
MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit)
|
||||||
|
@ -189,14 +189,14 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
|
|||||||
tx = tx.Omit(MassOmit...)
|
tx = tx.Omit(MassOmit...)
|
||||||
|
|
||||||
// запись
|
// запись
|
||||||
tx = tx.Create(&m)
|
tx = tx.Save(&m)
|
||||||
err = tx.Error
|
err = tx.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//удалим из кэша
|
//удалим из кэша
|
||||||
//cache.Remove(m.ID)
|
//cache.Remove(IntFromAlias(m.ID))
|
||||||
|
|
||||||
//запишем NULL в пустые колонки
|
//запишем NULL в пустые колонки
|
||||||
MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit)
|
MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit)
|
||||||
@ -237,7 +237,7 @@ func Delete_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui
|
|||||||
}
|
}
|
||||||
|
|
||||||
m2 := lawsuit_status_types.LawsuitStatusType{}
|
m2 := lawsuit_status_types.LawsuitStatusType{}
|
||||||
m2.ID = int64(m.ID)
|
m2.ID = m.ID
|
||||||
err = Read_ctx(ctx, db, &m2)
|
err = Read_ctx(ctx, db, &m2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -278,7 +278,7 @@ func Restore_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsu
|
|||||||
}
|
}
|
||||||
|
|
||||||
m2 := lawsuit_status_types.LawsuitStatusType{}
|
m2 := lawsuit_status_types.LawsuitStatusType{}
|
||||||
m2.ID = int64(m.ID)
|
m2.ID = m.ID
|
||||||
err = Read_ctx(ctx, db, &m2)
|
err = Read_ctx(ctx, db, &m2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -50,7 +50,7 @@ func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error {
|
|||||||
var versionModel = crud.GetVersionModel()
|
var versionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
Request := &grpc_proto.RequestId{}
|
Request := &grpc_proto.RequestId{}
|
||||||
Request.ID = int64(m.ID)
|
Request.ID = IntFromAlias(m.ID)
|
||||||
Request.VersionModel = versionModel
|
Request.VersionModel = versionModel
|
||||||
|
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
@ -230,7 +230,7 @@ func (crud Crud_GRPC) Delete(m *lawsuit_status_types.LawsuitStatusType) error {
|
|||||||
var VersionModel = crud.GetVersionModel()
|
var VersionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
Request := &grpc_proto.RequestId{}
|
Request := &grpc_proto.RequestId{}
|
||||||
Request.ID = int64(m.ID)
|
Request.ID = IntFromAlias(m.ID)
|
||||||
Request.VersionModel = VersionModel
|
Request.VersionModel = VersionModel
|
||||||
|
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
@ -272,7 +272,7 @@ func (crud Crud_GRPC) Restore(m *lawsuit_status_types.LawsuitStatusType) error {
|
|||||||
var VersionModel = crud.GetVersionModel()
|
var VersionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
Request := &grpc_proto.RequestId{}
|
Request := &grpc_proto.RequestId{}
|
||||||
Request.ID = int64(m.ID)
|
Request.ID = IntFromAlias(m.ID)
|
||||||
Request.VersionModel = VersionModel
|
Request.VersionModel = VersionModel
|
||||||
|
|
||||||
ctxMain := context.Background()
|
ctxMain := context.Background()
|
||||||
|
@ -20,7 +20,7 @@ func TestReadFromCache(t *testing.T) {
|
|||||||
t.Error("ReadFromCache() error: ", err)
|
t.Error("ReadFromCache() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("ReadFromCache() error: ID =0")
|
t.Error("ReadFromCache() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func TestRead(t *testing.T) {
|
|||||||
t.Error("TestRead() error: ", err)
|
t.Error("TestRead() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestRead() error: ID =0")
|
t.Error("TestRead() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,9 +53,6 @@ func TestCreate(t *testing.T) {
|
|||||||
t.Error("TestCreate() error: ", err)
|
t.Error("TestCreate() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) != 0 {
|
|
||||||
t.Error("TestCreate() error: ID !=0")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
@ -64,7 +61,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
defer grpc_client.CloseConnection()
|
defer grpc_client.CloseConnection()
|
||||||
|
|
||||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||||
Otvet.ID = -1
|
Otvet.ID = 0
|
||||||
|
|
||||||
crud := Crud_GRPC{}
|
crud := Crud_GRPC{}
|
||||||
err := crud.Update(&Otvet)
|
err := crud.Update(&Otvet)
|
||||||
@ -73,7 +70,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
t.Error("TestUpdate() error: ", err)
|
t.Error("TestUpdate() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) != 0 {
|
if IntFromAlias(Otvet.ID) != 0 {
|
||||||
t.Error("TestUpdate() error: ID =0")
|
t.Error("TestUpdate() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +95,7 @@ func TestSave(t *testing.T) {
|
|||||||
t.Error("TestSave() error: ", err)
|
t.Error("TestSave() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestSave() error: ID =0")
|
t.Error("TestSave() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +118,7 @@ func TestDelete(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("TestDelete() error: ", err)
|
t.Error("TestDelete() error: ", err)
|
||||||
}
|
}
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestDelete() error: ID =0")
|
t.Error("TestDelete() error: ID =0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +126,7 @@ func TestDelete(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("TestDelete() error: ", err)
|
t.Error("TestDelete() error: ", err)
|
||||||
}
|
}
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestDelete() error: ID =0")
|
t.Error("TestDelete() error: ID =0")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -137,7 +134,7 @@ func TestDelete(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("TestDelete() error: ", err)
|
t.Error("TestDelete() error: ", err)
|
||||||
}
|
}
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestDelete() error: ID =0")
|
t.Error("TestDelete() error: ID =0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +142,7 @@ func TestDelete(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("TestDelete() error: ", err)
|
t.Error("TestDelete() error: ", err)
|
||||||
}
|
}
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestDelete() error: ID =0")
|
t.Error("TestDelete() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +175,7 @@ func TestFindByExtID(t *testing.T) {
|
|||||||
t.Error("TestFindByExtID() error: ", err)
|
t.Error("TestFindByExtID() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestFindByExtID() error: ID =0")
|
t.Error("TestFindByExtID() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ func (crud Crud_GRPC) Update(m *lawsuit_status_types.LawsuitStatusType) error {
|
|||||||
var versionModel = crud.GetVersionModel()
|
var versionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
Request := &grpc_proto.RequestId{}
|
Request := &grpc_proto.RequestId{}
|
||||||
Request.ID = int64(m.ID)
|
Request.ID = IntFromAlias(m.ID)
|
||||||
Request.FieldName = m.ColumnName
|
Request.FieldName = m.ColumnName
|
||||||
Request.VersionModel = versionModel
|
Request.VersionModel = versionModel
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
func TestCrud_GRPC_Update(t *testing.T) {
|
func TestCrud_GRPC_Update(t *testing.T) {
|
||||||
config_main.LoadEnv()
|
config_main.LoadEnv()
|
||||||
|
|
||||||
postgres_gorm.Connect_WithApplicationName(constants.SERVICE_NAME + "_test")
|
grpc_client.Connect()
|
||||||
defer grpc_client.CloseConnection()
|
defer grpc_client.CloseConnection()
|
||||||
|
|
||||||
crud := Crud_GRPC{}
|
crud := Crud_GRPC{}
|
||||||
|
@ -29,7 +29,7 @@ func TestCrud_GRPC_UpdateManyFields(t *testing.T) {
|
|||||||
t.Error("TestCrud_GRPC_UpdateManyFields() error: ", err)
|
t.Error("TestCrud_GRPC_UpdateManyFields() error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(Otvet.ID) == 0 {
|
if IntFromAlias(Otvet.ID) == 0 {
|
||||||
t.Error("TestCrud_GRPC_UpdateManyFields() error: ID =0")
|
t.Error("TestCrud_GRPC_UpdateManyFields() error: ID =0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package grpc_client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsRecordNotFound(t *testing.T) {
|
func TestIsRecordNotFound(t *testing.T) {
|
||||||
|
|
||||||
err := errors.New(constants.TEXT_RECORD_NOT_FOUND + " !")
|
err := errors.New(db_constants.TEXT_RECORD_NOT_FOUND + " !")
|
||||||
Otvet := IsRecordNotFound(err)
|
Otvet := IsRecordNotFound(err)
|
||||||
if Otvet != true {
|
if Otvet != true {
|
||||||
t.Error("TestIsRecordNotFound() error: false")
|
t.Error("TestIsRecordNotFound() error: false")
|
||||||
|
@ -56,7 +56,7 @@ const GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME = "grpc_client_table_update_fu
|
|||||||
|
|
||||||
const CRUD_TABLES_CACHE_FILENAME = "crud_table_cache.go_"
|
const CRUD_TABLES_CACHE_FILENAME = "crud_table_cache.go_"
|
||||||
const CRUD_TABLES_CACHE_TEST_FILENAME = "crud_table_cache_test.go_"
|
const CRUD_TABLES_CACHE_TEST_FILENAME = "crud_table_cache_test.go_"
|
||||||
const TEXT_CACHE_REMOVE = "cache.Remove(m.ID)"
|
const TEXT_CACHE_REMOVE = "cache.Remove("
|
||||||
|
|
||||||
const SERVER_GRPC_TABLE_CACHE_FILENAME = "server_grpc_table_cache.go_"
|
const SERVER_GRPC_TABLE_CACHE_FILENAME = "server_grpc_table_cache.go_"
|
||||||
const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_"
|
const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_"
|
||||||
|
@ -191,36 +191,48 @@ func FindPrimaryKeyColumn(Table1 *types.Table) (Column1 *types.Column) {
|
|||||||
func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string {
|
func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string {
|
||||||
Otvet := Text
|
Otvet := Text
|
||||||
|
|
||||||
ColumnName, ColumnTypeGo := FindPrimaryKeyNameTypeGo(Table1)
|
ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1)
|
||||||
|
|
||||||
//заменим ID-Alias на ID
|
//заменим ID-Alias на ID
|
||||||
TableName := Table1.Name
|
TableName := Table1.Name
|
||||||
IDName, _ := FindPrimaryKeyNameType(Table1)
|
IDName, _ := FindPrimaryKeyNameType(Table1)
|
||||||
_, ok := types.MapConvertID[TableName+"."+IDName]
|
Alias, ok := types.MapConvertID[TableName+"."+IDName]
|
||||||
OtvetColumnName := "Otvet." + ColumnName
|
OtvetColumnName := "Otvet." + ColumnNamePK
|
||||||
if ok == true {
|
if ok == true {
|
||||||
OtvetColumnName = ColumnTypeGo + "(" + OtvetColumnName + ")"
|
OtvetColumnName = Alias + "(" + OtvetColumnName + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
//заменим int64(Otvet.ID) на Otvet.ID
|
//заменим int64(Otvet.ID) на Otvet.ID
|
||||||
if mini_func.IsNumberType(ColumnTypeGo) == true {
|
if mini_func.IsNumberType(ColumnTypeGoPK) == true {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
||||||
} else if ColumnTypeGo == "string" {
|
} else if ColumnTypeGoPK == "string" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == \"\"")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == \"\"")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != \"\"")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != \"\"")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
||||||
} else if ColumnTypeGo == "uuid.UUID" || ColumnTypeGo == "uuid.NullUUID" {
|
} else if ColumnTypeGoPK == "uuid.UUID" || ColumnTypeGoPK == "uuid.NullUUID" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == uuid.Nil")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+" == uuid.Nil")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != uuid.Nil")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+" != uuid.Nil")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
||||||
} else if ColumnTypeGo == "time.Time" {
|
} else if ColumnTypeGoPK == "time.Time" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+".IsZero() == true")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) == 0", OtvetColumnName+".IsZero() == true")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+".IsZero() == false")
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID) != 0", OtvetColumnName+".IsZero() == false")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(Otvet.ID)", OtvetColumnName)
|
||||||
}
|
}
|
||||||
Otvet = strings.ReplaceAll(Otvet, "Otvet.ID = ", OtvetColumnName+" = ")
|
//Otvet = strings.ReplaceAll(Otvet, "Otvet.ID = ", OtvetColumnName+" = ")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "Otvet.ID != ", OtvetColumnName+" != ")
|
//Otvet = strings.ReplaceAll(Otvet, "Otvet.ID != ", OtvetColumnName+" != ")
|
||||||
Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " "+OtvetColumnName+")")
|
//Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " "+OtvetColumnName+")")
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " Otvet."+ColumnNamePK+")")
|
||||||
|
|
||||||
|
//Alias преобразуем в int64, и наоборот
|
||||||
|
if Alias != "" {
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(Otvet.ID)", ColumnTypeGoPK+"(Otvet."+ColumnNamePK+")")
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(Otvet.ID)", OtvetColumnName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", Alias+"("+ColumnNamePK+")")
|
||||||
|
} else {
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(Otvet.ID)", "Otvet."+ColumnNamePK+"")
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(Otvet.ID)", OtvetColumnName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", "ID")
|
||||||
|
}
|
||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
@ -229,38 +241,48 @@ func ReplacePrimaryKeyOtvetID(Text string, Table1 *types.Table) string {
|
|||||||
func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string {
|
func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string {
|
||||||
Otvet := Text
|
Otvet := Text
|
||||||
|
|
||||||
ColumnName, ColumnTypeGo := FindPrimaryKeyNameTypeGo(Table1)
|
ColumnNamePK, ColumnTypeGoPK := FindPrimaryKeyNameTypeGo(Table1)
|
||||||
|
|
||||||
//заменим ID-Alias на ID
|
//заменим ID-Alias на ID
|
||||||
TableName := Table1.Name
|
TableName := Table1.Name
|
||||||
IDName, _ := FindPrimaryKeyNameType(Table1)
|
IDName, _ := FindPrimaryKeyNameType(Table1)
|
||||||
Alias, ok := types.MapConvertID[TableName+"."+IDName]
|
Alias, ok := types.MapConvertID[TableName+"."+IDName]
|
||||||
OtvetColumnName := "m." + ColumnName
|
OtvetColumnName := "m." + ColumnNamePK
|
||||||
if ok == true {
|
if ok == true {
|
||||||
OtvetColumnName = Alias + "(" + OtvetColumnName + ")"
|
OtvetColumnName = Alias + "(" + OtvetColumnName + ")"
|
||||||
//OtvetColumnName = ColumnTypeGo + "(" + OtvetColumnName + ")"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//заменим int64(m.ID) на m.ID
|
//заменим int64(m.ID) на m.ID
|
||||||
if mini_func.IsNumberType(ColumnTypeGo) == true {
|
if mini_func.IsNumberType(ColumnTypeGoPK) == true {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
||||||
} else if ColumnTypeGo == "string" {
|
} else if ColumnTypeGoPK == "string" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == \"\"")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == \"\"")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != \"\"")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != \"\"")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
||||||
} else if ColumnTypeGo == "uuid.UUID" || ColumnTypeGo == "uuid.NullUUID" {
|
} else if ColumnTypeGoPK == "uuid.UUID" || ColumnTypeGoPK == "uuid.NullUUID" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == uuid.Nil")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+" == uuid.Nil")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != uuid.Nil")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+" != uuid.Nil")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName+".String()")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName+".String()")
|
||||||
} else if ColumnTypeGo == "time.Time" {
|
} else if ColumnTypeGoPK == "time.Time" {
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+".IsZero() == true")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", OtvetColumnName+".IsZero() == true")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+".IsZero() == false")
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", OtvetColumnName+".IsZero() == false")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", OtvetColumnName)
|
||||||
}
|
}
|
||||||
Otvet = strings.ReplaceAll(Otvet, "m.ID = ", OtvetColumnName+" = ")
|
//Otvet = strings.ReplaceAll(Otvet, "m.ID = ", OtvetColumnName+" = ")
|
||||||
Otvet = strings.ReplaceAll(Otvet, " = m.ID", " = "+OtvetColumnName)
|
//Otvet = strings.ReplaceAll(Otvet, " = m.ID", " = "+OtvetColumnName)
|
||||||
Otvet = strings.ReplaceAll(Otvet, ", m.ID,", ", "+OtvetColumnName+",")
|
Otvet = strings.ReplaceAll(Otvet, ", m.ID,", ", "+OtvetColumnName+",")
|
||||||
Otvet = strings.ReplaceAll(Otvet, "(m.ID)", "("+OtvetColumnName+")")
|
//Otvet = strings.ReplaceAll(Otvet, "(m.ID)", "("+OtvetColumnName+")")
|
||||||
|
|
||||||
|
//Alias преобразуем в int64, и наоборот
|
||||||
|
if Alias != "" {
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(m.ID)", ColumnTypeGoPK+"(m."+ColumnNamePK+")")
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(m.ID)", OtvetColumnName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", Alias+"("+ColumnNamePK+")")
|
||||||
|
} else {
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntFromAlias(m.ID)", "m."+ColumnNamePK+"")
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(m.ID)", OtvetColumnName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "IntToAlias(ID)", "ID")
|
||||||
|
}
|
||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,9 @@ func CreateFiles(Table1 *types.Table) error {
|
|||||||
//uuid
|
//uuid
|
||||||
TextDB = create_files.CheckAndAddImportUUID_FromText(TextDB)
|
TextDB = create_files.CheckAndAddImportUUID_FromText(TextDB)
|
||||||
|
|
||||||
|
//alias
|
||||||
|
TextDB = create_files.CheckAndAddImportAlias(TextDB)
|
||||||
|
|
||||||
//удаление пустого импорта
|
//удаление пустого импорта
|
||||||
TextDB = create_files.DeleteEmptyImport(TextDB)
|
TextDB = create_files.DeleteEmptyImport(TextDB)
|
||||||
|
|
||||||
|
@ -242,9 +242,6 @@ func CreateFilesTest(Table1 *types.Table) error {
|
|||||||
}
|
}
|
||||||
TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1)
|
TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1)
|
||||||
|
|
||||||
// замена ID на PrimaryKey
|
|
||||||
TextGRPCClient = create_files.ReplacePrimaryKeyOtvetID(TextGRPCClient, Table1)
|
|
||||||
|
|
||||||
//SkipNow()
|
//SkipNow()
|
||||||
TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1)
|
TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1)
|
||||||
|
|
||||||
@ -603,6 +600,9 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error {
|
|||||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||||
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL)
|
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL)
|
||||||
|
|
||||||
|
//ConstantsURL := create_files.FindConstantsURL()
|
||||||
|
//TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ConstantsURL)
|
||||||
|
|
||||||
//TextGRPC_Client = create_files.ConvertRequestIdToAlias(TextGRPC_Client, Table1)
|
//TextGRPC_Client = create_files.ConvertRequestIdToAlias(TextGRPC_Client, Table1)
|
||||||
|
|
||||||
TextGRPC_Client = create_files.ReplacePrimaryKeyOtvetID(TextGRPC_Client, Table1)
|
TextGRPC_Client = create_files.ReplacePrimaryKeyOtvetID(TextGRPC_Client, Table1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user