mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-02-15 11:52:37 +02:00
сделал uuid
This commit is contained in:
parent
336fdde8ec
commit
f8eac549e3
@ -22,10 +22,11 @@ func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc
|
||||
defer ctxCancelFunc()
|
||||
|
||||
//запрос в БД
|
||||
value := Request.FieldName
|
||||
db := postgres_gorm.GetConnection()
|
||||
Model := &lawsuit_status_types.LawsuitStatusType{}
|
||||
Model.ID = Request.ID
|
||||
Model.ColumnName = Request.FieldName
|
||||
Model.ColumnName = value
|
||||
err = crud_lawsuit_status_types.Update_ColumnName_ctx(ctx, db, Model)
|
||||
if err != nil {
|
||||
return &Otvet, err
|
||||
|
@ -39,7 +39,6 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
||||
} else {
|
||||
tx = db.Model(&m).Update("ColumnName", Value)
|
||||
}
|
||||
|
||||
err = tx.Error
|
||||
if err != nil {
|
||||
err = fmt.Errorf(m.TableNameDB()+" Read() id: %v, error: %v", m.ID, err)
|
||||
|
@ -448,12 +448,13 @@ func FindTextDefaultGORMValue(Column1 *types.Column) string {
|
||||
ColumnName := Column1.Name
|
||||
|
||||
//ищем в файле настроек nullable.json
|
||||
is_nullable_config, has_is_nullable_config := types.MapNullableFileds[ColumnName]
|
||||
is_nullable_config, _ := types.MapNullableFileds[ColumnName]
|
||||
|
||||
//
|
||||
sValue := ""
|
||||
Type_go := Column1.TypeGo
|
||||
if Column1.TableKey != "" && Column1.IsNullable == true && (is_nullable_config == true || has_is_nullable_config == false) {
|
||||
// if Column1.TableKey != "" && Column1.IsNullable == true && (is_nullable_config == true || has_is_nullable_config == false) {
|
||||
if Column1.IsNullable == true || (is_nullable_config == true) {
|
||||
sValue = "null"
|
||||
} else {
|
||||
|
||||
@ -490,7 +491,7 @@ func FindTextDefaultValue(Type_go string) string {
|
||||
case "bool":
|
||||
Otvet = "false"
|
||||
case "uuid.UUID", "uuid.NullUUID":
|
||||
Otvet = "nil"
|
||||
Otvet = "uuid.Nil"
|
||||
}
|
||||
|
||||
return Otvet
|
||||
@ -510,7 +511,7 @@ func FindTextDefaultValueSQL(Type_go string) string {
|
||||
case "bool":
|
||||
Otvet = "false"
|
||||
case "uuid.UUID", "uuid.NullUUID":
|
||||
Otvet = "nil"
|
||||
Otvet = "null"
|
||||
}
|
||||
|
||||
return Otvet
|
||||
@ -1128,6 +1129,11 @@ func FindTextProtobufRequest(TypeGo string) (string, string) {
|
||||
Otvet = "RequestString"
|
||||
TextRequestFieldName = "StringFind"
|
||||
}
|
||||
case "uuid.UUID":
|
||||
{
|
||||
Otvet = "RequestString"
|
||||
TextRequestFieldName = "StringFind"
|
||||
}
|
||||
case "time.Time":
|
||||
{
|
||||
Otvet = "RequestDate"
|
||||
@ -1158,10 +1164,12 @@ func FindTextProtobufRequest(TypeGo string) (string, string) {
|
||||
// Otvet - имя message из .proto
|
||||
// TextRequestFieldName - название поля в Request
|
||||
// TextRequestFieldGolang - название поля в Request с преобразованием в тип гоу
|
||||
func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, VariableName string) (string, string, string) {
|
||||
// TextGolangLine - замена всей строки в го
|
||||
func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, VariableName string) (string, string, string, string) {
|
||||
Otvet := "RequestID"
|
||||
TextRequestFieldName := "ID"
|
||||
TextRequestFieldGolang := "ID"
|
||||
TextGolangLine := ""
|
||||
|
||||
TypeGo := Column1.TypeGo
|
||||
TableName := Table1.Name
|
||||
@ -1187,6 +1195,21 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column,
|
||||
TextRequestFieldName = "StringFind"
|
||||
TextRequestFieldGolang = VariableName + "StringFind"
|
||||
}
|
||||
case "uuid.UUID":
|
||||
{
|
||||
Otvet = "Request_ID_String"
|
||||
TextRequestFieldName = "StringFind"
|
||||
TextRequestFieldGolang = VariableName + "StringFind"
|
||||
TextGolangLine = "value, err := uuid.Parse(" + VariableName + "" + TextRequestFieldName + ")" + `
|
||||
if Request.StringFind == "" {
|
||||
value = uuid.Nil
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
return &Otvet, err
|
||||
}
|
||||
`
|
||||
}
|
||||
case "time.Time":
|
||||
{
|
||||
Otvet = "Request_ID_Date"
|
||||
@ -1218,7 +1241,7 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column,
|
||||
TextRequestFieldGolang = TextConvert + "(" + VariableName + TextRequestFieldName + ")"
|
||||
}
|
||||
|
||||
return Otvet, TextRequestFieldName, TextRequestFieldGolang
|
||||
return Otvet, TextRequestFieldName, TextRequestFieldGolang, TextGolangLine
|
||||
}
|
||||
|
||||
// ConvertRequestIdToAlias - заменяет ID на Alias
|
||||
@ -1325,6 +1348,8 @@ func FindTextConvertGolangTypeToProtobufType(Table1 *types.Table, Column1 *types
|
||||
Otvet = "float32(" + VariableName + Column1.NameGo + ")"
|
||||
case "float64":
|
||||
Otvet = "float64(" + VariableName + Column1.NameGo + ")"
|
||||
case "uuid.UUID":
|
||||
Otvet = VariableName + Column1.NameGo + ".String()"
|
||||
}
|
||||
|
||||
return Otvet
|
||||
@ -1345,10 +1370,22 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types
|
||||
}
|
||||
|
||||
//time.Time в timestamppb
|
||||
if Column1.TypeGo == "time.Time" {
|
||||
Otvet = VariableName + Column1.NameGo + ".AsTime()"
|
||||
return Otvet
|
||||
switch Column1.TypeGo {
|
||||
case "time.Time":
|
||||
{
|
||||
Otvet = VariableName + Column1.NameGo + ".AsTime()"
|
||||
return Otvet
|
||||
}
|
||||
case "uuid.UUID":
|
||||
{
|
||||
Otvet = "uuid.FromBytes([]byte(" + VariableName + Column1.NameGo + "))"
|
||||
return Otvet
|
||||
}
|
||||
}
|
||||
//if Column1.TypeGo == "time.Time" {
|
||||
// Otvet = VariableName + Column1.NameGo + ".AsTime()"
|
||||
// return Otvet
|
||||
//}
|
||||
|
||||
////преобразуем alias в обычный тип, и дату в timestamp
|
||||
//switch Column1.TypeGo {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package db_crud_tables
|
||||
package crud_tables
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
@ -532,19 +532,6 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_MODEL, Table1.NameGo)
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
|
||||
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextCrud = create_files.AddImport(TextCrud, DBConstantsURL)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextCrudUpdateFunc, Table1)
|
||||
|
||||
@ -556,6 +543,20 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
TextCrud = TextCrud + TextUpdateEveryColumn
|
||||
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
|
||||
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextCrud = create_files.AddImport(TextCrud, DBConstantsURL)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
TextCrud = create_files.CheckAndAddImportUUID_FromText(TextCrud)
|
||||
//TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1)
|
||||
}
|
||||
|
||||
//кэш
|
||||
if config.Settings.NEED_CREATE_CACHE_API == true {
|
||||
TextCrud = strings.ReplaceAll(TextCrud, `//`+constants.TEXT_CACHE_REMOVE, constants.TEXT_CACHE_REMOVE)
|
1
internal/create_files/crud_tables/crud_tables_test.go
Normal file
1
internal/create_files/crud_tables/crud_tables_test.go
Normal file
@ -0,0 +1 @@
|
||||
package crud_tables
|
@ -1 +0,0 @@
|
||||
package db_crud_tables
|
@ -1 +0,0 @@
|
||||
package db_tables
|
@ -1,4 +1,4 @@
|
||||
package model_tables
|
||||
package entities_tables
|
||||
|
||||
import (
|
||||
"errors"
|
@ -0,0 +1 @@
|
||||
package entities_tables
|
@ -495,7 +495,7 @@ 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.")
|
||||
TextRequest, TextRequestFieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
|
||||
|
||||
ColumnNameGolang := create_files.FindTextConvertGolangTypeToProtobufType(Table1, Column1, "m.")
|
||||
|
||||
@ -641,7 +641,7 @@ func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *ty
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest, TextRequestFieldName, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
|
||||
TextRequest, TextRequestFieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
|
||||
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||
|
||||
Otvet = strings.ReplaceAll(Otvet, "TestCrud_GRPC_Update(", "TestCrud_GRPC_"+FuncName+"(")
|
||||
|
@ -1 +0,0 @@
|
||||
package grpc_server_tables
|
@ -1 +0,0 @@
|
||||
package model_tables
|
@ -376,7 +376,7 @@ func TextUpdateEveryColumn(Table1 *types.Table, Column1 *types.Column) string {
|
||||
|
||||
TextRequest := ""
|
||||
//TypeGo := Column1.TypeGo
|
||||
TextRequest, _, _ = create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "")
|
||||
TextRequest, _, _, _ = create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "")
|
||||
ColumnName := Column1.NameGo
|
||||
|
||||
Otvet = "rpc " + ModelName + "_Update_" + ColumnName + "(" + TextRequest + ") returns (ResponseEmpty) {}"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package grpc_server_tables
|
||||
package server_grpc_tables
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
@ -427,6 +427,9 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
|
||||
}
|
||||
|
||||
//import uuid
|
||||
TextGRPCServer = create_files.CheckAndAddImportUUID_FromText(TextGRPCServer)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer)
|
||||
|
||||
@ -475,13 +478,16 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest, _, TextRequestFieldGolang := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
|
||||
TextRequest, _, TextRequestFieldGolang, TextGolangLine := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request.")
|
||||
|
||||
//ColumnNameGolang := create_files.FindTextConvertGolangTypeToProtobufType(Table1, Column1, "m.")
|
||||
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update", ModelName+"_"+FuncName)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
if TextGolangLine != "" {
|
||||
Otvet = strings.ReplaceAll(Otvet, "value := Request.FieldName", TextGolangLine)
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Request.FieldName", TextRequestFieldGolang)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Model.ColumnName", "Model."+ColumnName)
|
||||
@ -615,9 +621,12 @@ func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *typ
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest2, TextRequestField, TextRequestFieldGolang := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request2.")
|
||||
TextRequest2, TextRequestField, TextRequestFieldGolang, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "Request2.")
|
||||
TextModelColumnName := create_files.FindTextConvertGolangTypeToProtobufType(Table1, Column1, "Model.")
|
||||
|
||||
//if TextGolangLine != "" {
|
||||
// Otvet = strings.ReplaceAll(Otvet, "value := Request.FieldName", TextGolangLine)
|
||||
//}
|
||||
Otvet = strings.ReplaceAll(Otvet, "Request2.ColumnName", "Request2."+TextRequestField)
|
||||
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestString", "grpc_proto."+TextRequest2)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update(", ModelName+"_"+FuncName+"(")
|
@ -0,0 +1 @@
|
||||
package server_grpc_tables
|
@ -1,4 +1,4 @@
|
||||
package db_tables
|
||||
package tables_tables
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -91,8 +91,13 @@ func CreateFilesTable_struct(Table1 *types.Table, DirTemplatesTable, DirReadyTab
|
||||
}
|
||||
TextModel = DeleteFuncFind_byExtID(TextModel, ModelName, Table1)
|
||||
|
||||
//import time
|
||||
TextModel = create_files.CheckAndAddImportTime_FromText(TextModel)
|
||||
|
||||
//import uuid
|
||||
TextModel = create_files.CheckAndAddImportUUID_FromText(TextModel)
|
||||
|
||||
//
|
||||
TextModel = create_files.DeleteImportModel(TextModel)
|
||||
|
||||
//замена импортов на новые URL
|
||||
@ -219,7 +224,7 @@ func FindTextColumn(TextModel string, Table1 *types.Table, Column1 *types.Column
|
||||
if Column1.IsPrimaryKey == false {
|
||||
TextDefaultValue = create_files.FindTextDefaultGORMValue(Column1)
|
||||
}
|
||||
TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity)
|
||||
TextPrimaryKey := FindTextPrimaryKey(Column1.IsPrimaryKey)
|
||||
Description := Column1.Description
|
||||
Description = create_files.PrintableString(Description) //экранирование символов
|
||||
|
@ -0,0 +1 @@
|
||||
package tables_tables
|
@ -5,22 +5,22 @@ import (
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/alias"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/db_crud_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/db_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/entities_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/env_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/generation_code_sh"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_client"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_client_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_server_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/main_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/makefile"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/model_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/protobuf"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/readme_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_func"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_nrpc_starter"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/tables_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/folders"
|
||||
"github.com/ManyakRus/crud_generator/internal/postgres"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
@ -53,21 +53,21 @@ func StartFillAll() error {
|
||||
}
|
||||
|
||||
//модель
|
||||
err = model_tables.CreateAllFiles(MapAll)
|
||||
err = entities_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
//log.Error("model.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//db crud
|
||||
err = db_crud_tables.CreateAllFiles(MapAll)
|
||||
err = crud_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
//log.Error("db_crud_tables.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//grpc_server
|
||||
err = grpc_server_tables.CreateAllFiles(MapAll)
|
||||
err = server_grpc_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
//log.Error("grpc_server.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
@ -158,7 +158,7 @@ func StartFillAll() error {
|
||||
}
|
||||
|
||||
//tables
|
||||
err = db_tables.CreateAllFiles(MapAll)
|
||||
err = tables_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
//log.Error("db_tables.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user