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-04-26 16:45:09 +03:00
parent 41a2e64812
commit 024bef8be3
11 changed files with 116 additions and 103 deletions

View File

@ -32,15 +32,15 @@ func (s *ServerGRPC) LawsuitStatusType_UpdateManyFields(ctx context.Context, Req
}
//получим модель из строки JSON
Model := lawsuit_status_types.LawsuitStatusType{}
err = Model.GetModelFromJSON(Request.ModelString)
m := lawsuit_status_types.LawsuitStatusType{}
err = m.GetModelFromJSON(Request.ModelString)
if err != nil {
return &Otvet, err
}
//запрос в БД
db := postgres_gorm.GetConnection()
err = crud_lawsuit_status_types.UpdateManyFields_ctx(ctx, db, &Model, Request.MassNames)
err = crud_lawsuit_status_types.UpdateManyFields_ctx(ctx, db, &m, Request.MassNames)
if err != nil {
return &Otvet, err
}

View File

@ -25,10 +25,10 @@ func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc
value := Request.FieldName
db := postgres_gorm.GetConnection()
ID := Request.ID
Model := &lawsuit_status_types.LawsuitStatusType{}
Model.ID = ID
Model.ColumnName = value
err = crud_lawsuit_status_types.Update_ColumnName_ctx(ctx, db, Model)
m := &lawsuit_status_types.LawsuitStatusType{}
m.ID = ID
m.ColumnName = value
err = crud_lawsuit_status_types.Update_ColumnName_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}

View File

@ -16,8 +16,8 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
if Response1.ModelString == "" {
t.Error("Test_server_LawsuitStatusType_Update() Read() error: ModelString=''")
}
Model := lawsuit_status_types.LawsuitStatusType{}
err = Model.GetModelFromJSON(Response1.ModelString)
m := lawsuit_status_types.LawsuitStatusType{}
err = m.GetModelFromJSON(Response1.ModelString)
if err != nil {
t.Error("Test_server_LawsuitStatusType_Update_ColumnName() GetModelFromJSON() error: ", err)
}
@ -25,7 +25,7 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
//запишем в БД это же значение
Request2 := grpc_proto.RequestString{}
Request2.ID = LawsuitStatusType_ID_Test
Request2.ColumnName = Model.ColumnName
Request2.ColumnName = m.ColumnName
Request2.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
_, err = server1.LawsuitStatusType_Update_ColumnName(ctx, &Request2)
if err != nil {

View File

@ -103,9 +103,9 @@ func Test_server_LawsuitStatusType_Create(t *testing.T) {
crud_starter.InitCrudTransport_DB()
var ModelString string
Model := lawsuit_status_types.LawsuitStatusType{}
Model.ID = -1
ModelString, err := Model.GetJSON()
m := lawsuit_status_types.LawsuitStatusType{}
m.ID = -1
ModelString, err := m.GetJSON()
if err != nil {
t.Error("Test_server_LawsuitStatusType_Create() error: ", err)
return

View File

@ -1,5 +1,5 @@
if m.CreatedAt.IsZero() == true || m.ID == 0 {
if m.CreatedAt.IsZero() == true || int64(m.ID) == 0 {
m.CreatedAt = time.Now()
}

View File

@ -201,7 +201,7 @@ func create_update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types
}
//удалим из кэша
//cache.Remove(int64(m.ID))
//cache.Remove(m.ID)
//запишем NULL в пустые колонки
MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit)

View File

@ -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_TEST_FILENAME = "crud_table_cache_test.go_"
const TEXT_CACHE_REMOVE = "cache.Remove(int64(m.ID))"
const TEXT_CACHE_REMOVE = "cache.Remove(m.ID)"
const SERVER_GRPC_TABLE_CACHE_FILENAME = "server_grpc_table_cache.go_"
const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_"

View File

@ -1192,7 +1192,7 @@ func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string
PrimaryKeyTypeGo := PrimaryKeyColumn.TypeGo
switch PrimaryKeyTypeGo {
case "string", "uuid.UUID":
TextRequest = "RequestString_"
TextRequest = "Request"
}
switch TypeGo {
@ -1247,59 +1247,59 @@ func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string
return Otvet, TextRequestFieldName
}
// FindTextProtobufRequestPrimaryKey - возвращает "RequestID" и "ID" - имя message из .proto, в зависимости от типа, а также название поля
func FindTextProtobufRequestPrimaryKey(Table1 *types.Table, TypeGo string) (string, string) {
Otvet := "RequestId"
TextRequestFieldName := "ID"
TextRequest := "Request"
switch TypeGo {
case "int", "int64":
{
Otvet = TextRequest + "Id"
TextRequestFieldName = "ID"
}
case "int32":
{
Otvet = TextRequest + "Int32"
TextRequestFieldName = "Int32"
}
case "string":
{
Otvet = TextRequest + "String"
TextRequestFieldName = "String_1"
}
case "uuid.UUID":
{
Otvet = TextRequest + "String"
TextRequestFieldName = "String_1"
}
case "time.Time":
{
Otvet = TextRequest + "Date"
TextRequestFieldName = "Date"
}
case "float32":
{
Otvet = TextRequest + "Float32"
TextRequestFieldName = "Float32"
}
case "float64":
{
Otvet = TextRequest + "Float64"
TextRequestFieldName = "Float64"
}
case "bool":
{
Otvet = TextRequest + "Bool"
TextRequestFieldName = "Bool"
}
}
return Otvet, TextRequestFieldName
}
//// FindTextProtobufRequestPrimaryKey - возвращает "RequestID" и "ID" - имя message из .proto, в зависимости от типа, а также название поля
//func FindTextProtobufRequestPrimaryKey(Table1 *types.Table, TypeGo string) (string, string) {
// Otvet := "RequestId"
// TextRequestFieldName := "ID"
//
// TextRequest := "Request"
//
// switch TypeGo {
// case "int", "int64":
// {
// Otvet = TextRequest + "Id"
// TextRequestFieldName = "ID"
// }
//
// case "int32":
// {
// Otvet = TextRequest + "Int32"
// TextRequestFieldName = "Int32"
// }
// case "string":
// {
// Otvet = TextRequest + "String"
// TextRequestFieldName = "String_1"
// }
// case "uuid.UUID":
// {
// Otvet = TextRequest + "String"
// TextRequestFieldName = "String_1"
// }
// case "time.Time":
// {
// Otvet = TextRequest + "Date"
// TextRequestFieldName = "Date"
// }
// case "float32":
// {
// Otvet = TextRequest + "Float32"
// TextRequestFieldName = "Float32"
// }
// case "float64":
// {
// Otvet = TextRequest + "Float64"
// TextRequestFieldName = "Float64"
// }
// case "bool":
// {
// Otvet = TextRequest + "Bool"
// TextRequestFieldName = "Bool"
// }
// }
//
// return Otvet, TextRequestFieldName
//}
// FindTextProtobufRequest_ID_Type - возвращает имя message из .proto для двух параметров ID + Type,в зависимости от типа, а также название поля
// возвращает:
@ -1319,49 +1319,59 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column,
//найдём тип колонки PrimaryKey
PrimaryKey_Column := FindPrimaryKeyColumn(Table1)
//PrimaryKey_TypeGo := PrimaryKey_Column.TypeGo
PrimaryKey_TypeGo := PrimaryKey_Column.TypeGo
//Text_Request_ID := "Request_ID"
Otvet, _ = FindTextProtobufRequest(Table1, TypeGo)
Otvet, _ = FindTextProtobufRequest(Table1, PrimaryKey_TypeGo)
//Text_Request_ID = "Request_" + TextID
TextRequestProtoName := ""
//найдём строку по типу колонки
switch TypeGo {
case "int", "int64":
{
//Otvet = Text_Request_ID + "_Int64"
TextRequestProtoName = "Int64"
TextRequestFieldName = "Int64"
TextRequestFieldGolang = VariableName + "Int64"
}
case "int32":
{
//Otvet = Text_Request_ID + "_Int32"
TextRequestFieldName = "Int32"
TextRequestFieldGolang = VariableName + "Int32"
if Column1.TypeGo == "Int32" && PrimaryKey_Column.TypeGo == "Int32" {
TextRequestProtoName = "Int32"
TextRequestFieldName = "Int32_2"
TextRequestFieldGolang = VariableName + "Int32"
} else {
TextRequestProtoName = "Int32"
TextRequestFieldName = "Int32"
TextRequestFieldGolang = VariableName + "Int32"
}
}
case "string":
{
//Otvet = Text_Request_ID + "_String"
if Column1 != PrimaryKey_Column {
if Column1.TypeGo == "string" && PrimaryKey_Column.TypeGo == "string" {
TextRequestProtoName = "String"
TextRequestFieldName = "String_2"
TextRequestFieldGolang = VariableName + "String_2"
} else {
TextRequestProtoName = "String"
TextRequestFieldName = "String_1"
TextRequestFieldGolang = VariableName + "String_1"
}
}
case "uuid.UUID":
{
//Otvet = Text_Request_ID + "_String"
if Column1 != PrimaryKey_Column {
if Column1.TypeGo == "string" && PrimaryKey_Column.TypeGo == "string" {
TextRequestProtoName = "String"
TextRequestFieldName = "String_2"
TextRequestFieldGolang = VariableName + "String_2"
} else {
TextRequestProtoName = "String"
TextRequestFieldName = "String_1"
TextRequestFieldGolang = VariableName + "String_1"
}
TextGolangLine = "value, err := uuid.Parse(" + VariableName + "" + TextRequestFieldName + ")" + `
if Request.String_2 == "" {
if Request.` + TextRequestFieldName + ` == "" {
value = uuid.Nil
err = nil
}
@ -1372,25 +1382,25 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column,
}
case "time.Time":
{
//Otvet = Text_Request_ID + "_Date"
TextRequestProtoName = "Date"
TextRequestFieldName = "Date"
TextRequestFieldGolang = VariableName + "Date.AsTime()"
}
case "float32":
{
//Otvet = Text_Request_ID + "_Float32"
TextRequestProtoName = "Float32"
TextRequestFieldName = "Float32"
TextRequestFieldGolang = VariableName + "Float32"
}
case "float64":
{
//Otvet = Text_Request_ID + "_Float64"
TextRequestProtoName = "Float64"
TextRequestFieldName = "Float64"
TextRequestFieldGolang = VariableName + "Float64"
}
case "bool":
{
//Otvet = Text_Request_ID + "_Bool"
TextRequestProtoName = "Bool"
TextRequestFieldName = "Bool"
TextRequestFieldGolang = VariableName + "Bool"
}
@ -1401,6 +1411,8 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column,
TextRequestFieldGolang = TextConvert + "(" + VariableName + TextRequestFieldName + ")"
}
Otvet = Otvet + "_" + TextRequestProtoName
return Otvet, TextRequestFieldName, TextRequestFieldGolang, TextGolangLine
}
@ -1712,19 +1724,19 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string {
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = "`+IDMinimum+`"`)
}
} else {
Otvet = strings.ReplaceAll(Otvet, TextFind, TextFind+IDMinimum)
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum)
}
return Otvet
}
// ReplaceTextRequestID - заменяет RequestId{} на RequestString{}
func ReplaceTextRequestID(Text string, Table1 *types.Table, Column1 *types.Column) string {
// ReplaceTextRequestID_and_Column - заменяет RequestId{} на RequestString{}
func ReplaceTextRequestID_and_Column(Text string, Table1 *types.Table, Column1 *types.Column) string {
Otvet := Text
TypeGo := Column1.TypeGo
//TypeGo := Column1.TypeGo
TextRequestID, _ := FindTextProtobufRequest(Table1, TypeGo)
TextRequestID, _, _, _ := FindTextProtobufRequest_ID_Type(Table1, Column1, "Request")
Otvet = strings.ReplaceAll(Otvet, "RequestId{}", TextRequestID+"{}")
//Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID)
@ -1751,7 +1763,7 @@ func ReplaceTextRequestID_PrimaryKey1(Text string, Table1 *types.Table, TextRequ
PrimaryKeyColumn := FindPrimaryKeyColumn(Table1)
TypeGo := PrimaryKeyColumn.TypeGo
TextRequestID, TextID := FindTextProtobufRequestPrimaryKey(Table1, TypeGo)
TextRequestID, TextID := FindTextProtobufRequest(Table1, TypeGo)
_, GolangCode := FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.")
if GolangCode != "" {
@ -1799,7 +1811,7 @@ func ReplaceModelIDEqual1(Text string, Table1 *types.Table) string {
PrimaryKeyColumn := FindPrimaryKeyColumn(Table1)
Value := FindNegativeValue(PrimaryKeyColumn.TypeGo)
Otvet = strings.ReplaceAll(Otvet, "Model.ID = -1", "Model.ID = "+Value)
Otvet = strings.ReplaceAll(Otvet, "m.ID = -1", "m.ID = "+Value)
return Otvet
}

View File

@ -155,7 +155,6 @@ func CreateFiles(Table1 *types.Table) error {
//создание текста
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = create_files.ReplacePrimaryKeyM_ID(TextDB, Table1)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB
//TextDB = create_files.DeleteFuncFind_byExtID(TextDB, Table1)
@ -165,6 +164,7 @@ func CreateFiles(Table1 *types.Table) error {
TextDB = ReplaceText_created_at(TextDB, Table1)
TextDB = ReplaceText_is_deleted_deleted_at(TextDB, Table1)
TextDB = create_files.DeleteImportModel(TextDB)
TextDB = create_files.ReplacePrimaryKeyM_ID(TextDB, Table1)
//замена импортов на новые URL
TextDB = create_files.ReplaceServiceURLImports(TextDB)
@ -781,7 +781,7 @@ func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Tab
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName)
Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName)
Otvet = strings.ReplaceAll(Otvet, "Otvet.Name", "Otvet."+ColumnName)
//Otvet = strings.ReplaceAll(Otvet, "Otvet.Name", "Otvet."+ColumnName)
//Otvet = strings.ReplaceAll(Otvet, "Postgres_ID_Test", DefaultValue)
Otvet = strings.ReplaceAll(Otvet, "TestUpdate(", "Test"+FuncName+"(")
Otvet = strings.ReplaceAll(Otvet, ".Update(", "."+FuncName+"(")

View File

@ -516,10 +516,10 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types.
ModelName := Table1.NameGo
ColumnName := Column1.NameGo
FuncName := "Update_" + ColumnName
TextRequest, TextRequestFieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
_, TextRequestFieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
//замена RequestId{}
Otvet = create_files.ReplaceTextRequestID(Otvet, Table1, Column1)
Otvet = create_files.ReplaceTextRequestID_and_Column(Otvet, Table1, Column1)
Otvet = create_files.ReplaceTextRequestID_PrimaryKey(Otvet, Table1)
//замена ID на PrimaryKey
@ -535,7 +535,7 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types.
Otvet = strings.ReplaceAll(Otvet, " Update(", " "+FuncName+"(")
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
//Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
Otvet = strings.ReplaceAll(Otvet, "m.ColumnName", ColumnNameGolang)
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID)", " "+IDTypeGo+"(m.ID)")
Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName)
@ -629,7 +629,7 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error {
//
TextGRPC_Client = config.Settings.TEXT_MODULE_GENERATED + TextGRPC_Client
//TextGRPC_Client = create_files.ReplaceTextRequestID(TextGRPC_Client, Table1)
//TextGRPC_Client = create_files.ReplaceTextRequestID_and_Column(TextGRPC_Client, Table1)
//SkipNow() если нет строк в БД
TextGRPC_Client = create_files.AddSkipNow(TextGRPC_Client, Table1)
@ -679,7 +679,7 @@ func FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc string, Table1 *typ
func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
Otvet := TextGRPC_ClientUpdateFunc
Otvet = create_files.ReplaceTextRequestID(Otvet, Table1, Column1)
Otvet = create_files.ReplaceTextRequestID_and_Column(Otvet, Table1, Column1)
Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1)
Otvet = create_files.ReplacePrimaryKeyOtvetID(Otvet, Table1)

View File

@ -234,13 +234,14 @@ func CreateFilesTest(Table1 *types.Table) error {
TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
//Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" {
TextFind := "const " + ModelName + "_ID_Test = "
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"0", TextFind+Table1.IDMinimum)
}
//if Table1.IDMinimum != "" {
// TextFind := "const " + ModelName + "_ID_Test = "
// TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"0", TextFind+Table1.IDMinimum)
//}
// замена ID на PrimaryKey
TextGRPCServer = create_files.ReplacePrimaryKeyOtvetID(TextGRPCServer, Table1)
TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1)
//SkipNow()
TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1)