From 634d316da3cbcb6bd04532c8e9d20d2c6001cfc0 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 29 Nov 2023 15:06:50 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/templates/configs_/settings.txt | 24 ++++++++------- examples/rapira/templates/Makefile_ | 5 ++-- .../network/grpc => api}/generation_code.sh_ | 0 .../{pkg/network/grpc => api}/service.proto_ | 0 examples/rapira/templates/cmd/main.go_ | 1 - .../configs_/model_crud_delete_functions.json | 3 ++ .../rapira/templates/configs_/nullable.json | 4 +-- examples/rapira/templates/configs_/readme.txt | 30 +++++++++++++++++-- .../rapira/templates/configs_/settings.txt | 20 +++++++------ .../app/grpc/server_grpc/server_grpc.go_ | 1 - .../app/grpc/server_grpc/server_grpc_func.go_ | 2 +- .../grpc/server_grpc/server_grpc_starter.go_ | 1 - .../app/grpc/server_grpc/server_grpc_test.go_ | 1 - .../nrpc/server_nrpc/server_nrpc_starter.go_ | 18 +++++++++-- .../templates/pkg/db/constants/constants.go | 8 +++++ .../rapira/templates/pkg/db/crud/crud.go_ | 23 ++++++-------- .../pkg/db/crud_functions/crud_functions.go | 13 ++++++++ .../db/crud_functions/crud_functions_test.go | 1 + .../rapira/templates/pkg/db/tables/table.go_ | 1 - .../grpc/grpc_client/grpc_client_table.go_ | 1 - .../grpc_client/grpc_client_table_test.go_ | 1 - .../nrpc/nrpc_client/nrpc_client_table.go_ | 1 - .../nrpc_client/nrpc_client_table_test.go_ | 1 - .../pkg/object_model/entities/model.go_ | 1 - .../pkg/object_model/entities/model_crud.go_ | 29 ++++++++++++++++++ 25 files changed, 137 insertions(+), 53 deletions(-) rename examples/rapira/templates/{pkg/network/grpc => api}/generation_code.sh_ (100%) rename examples/rapira/templates/{pkg/network/grpc => api}/service.proto_ (100%) create mode 100644 examples/rapira/templates/configs_/model_crud_delete_functions.json create mode 100644 examples/rapira/templates/pkg/db/crud_functions/crud_functions.go create mode 100644 examples/rapira/templates/pkg/db/crud_functions/crud_functions_test.go diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index 5895bd0..6647da1 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -1,21 +1,21 @@ #---------------------Database settings--------------------- #DB_HOST - Database server name or ip-address. Only Postgres SQL -DB_HOST="" +DB_HOST= #DB_NAME - Database table name -DB_NAME="" +DB_NAME= #DB_SCHEME - Database schema name -DB_SCHEME="public" +DB_SCHEME= #DB_PORT - Database port number -DB_PORT="5432" +DB_PORT= #DB_USER - Database login (user) -DB_USER="" +DB_USER= #DB_PASSWORD - Database login password -DB_PASSWORD="" +DB_PASSWORD= #INCLUDE_TABLES - table name filter. Regular expression INCLUDE_TABLES="" @@ -53,24 +53,23 @@ TEMPLATE_FOLDERNAME_CRUD="pkg/db/crud" #TEMPLATE_FOLDERNAME_TABLES - folder name for create database tables models TEMPLATE_FOLDERNAME_TABLES="pkg/db/tables" -#TEMPLATE_FOLDERNAME_DB - folder name for create db constants +#TEMPLATE_FOLDERNAME_DB - folder name for create db TEMPLATE_FOLDERNAME_DB="pkg/db" - #TEMPLATE_FOLDERNAME_GRPC - folder name for create .proto file -TEMPLATE_FOLDERNAME_GRPC_PROTO="pkg/network/grpc" +TEMPLATE_FOLDERNAME_GRPC_PROTO="api" #TEMPLATE_FOLDERNAME_GRPC - folder name for grpc TEMPLATE_FOLDERNAME_GRPC="pkg/network/grpc" #TEMPLATE_FOLDERNAME_GRPC_SERVER - filder name for create grpc server files -TEMPLATE_FOLDERNAME_GRPC_SERVER="internal/server_grpc" +TEMPLATE_FOLDERNAME_GRPC_SERVER="internal/app/grpc/server_grpc" #TEMPLATE_FOLDERNAME_GRPC_CLIENT - folder name for create grpc client files TEMPLATE_FOLDERNAME_GRPC_CLIENT="pkg/network/grpc/grpc_client" #TEMPLATE_FOLDERNAME_NRPC_SERVER - folder name for create nrpc server files -TEMPLATE_FOLDERNAME_NRPC_SERVER="internal/server_nrpc" +TEMPLATE_FOLDERNAME_NRPC_SERVER="internal/app/nrpc/server_nrpc" #TEMPLATE_FOLDERNAME_NRPC - folder name for create common nrpc files TEMPLATE_FOLDERNAME_NRPC="pkg/network/nrpc" @@ -84,6 +83,9 @@ TEMPLATE_FOLDERNAME_CRUD_STARTER="pkg/crud_starter" #TEMPLATE_FOLDERNAME_ALIAS - folder name for create alias.go file, with go types with aliases TEMPLATE_FOLDERNAME_ALIAS="pkg/object_model/types/alias" +#TEMPLATE_FOLDER_CRUD_FUNCTIONS - folder name for create crud_functions.go file +TEMPLATE_FOLDER_CRUD_FUNCTIONS="pkg/db/crud_functions" + #TEXT_TEMPLATE_MODEL - model name text in templates, for replace to new model names TEXT_TEMPLATE_MODEL="LawsuitStatusType" diff --git a/examples/rapira/templates/Makefile_ b/examples/rapira/templates/Makefile_ index 96ce3fb..a7db086 100644 --- a/examples/rapira/templates/Makefile_ +++ b/examples/rapira/templates/Makefile_ @@ -5,7 +5,7 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go FILEAPP=./bin/$(SERVICENAME) NEW_REPO=$(SERVICENAME) -CD_GENERATION_PROTO=cd ./pkg/network/grpc +CD_GENERATION_PROTO=cd ./api GENERATION_PROTO=generation_code.sh @@ -56,4 +56,5 @@ init: go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service $(CD_GENERATION_PROTO) $(GENERATION_PROTO) - go mod tidy \ No newline at end of file + go mod tidy + go mod vendor \ No newline at end of file diff --git a/examples/rapira/templates/pkg/network/grpc/generation_code.sh_ b/examples/rapira/templates/api/generation_code.sh_ similarity index 100% rename from examples/rapira/templates/pkg/network/grpc/generation_code.sh_ rename to examples/rapira/templates/api/generation_code.sh_ diff --git a/examples/rapira/templates/pkg/network/grpc/service.proto_ b/examples/rapira/templates/api/service.proto_ similarity index 100% rename from examples/rapira/templates/pkg/network/grpc/service.proto_ rename to examples/rapira/templates/api/service.proto_ diff --git a/examples/rapira/templates/cmd/main.go_ b/examples/rapira/templates/cmd/main.go_ index 481065a..8e9fa2d 100644 --- a/examples/rapira/templates/cmd/main.go_ +++ b/examples/rapira/templates/cmd/main.go_ @@ -25,4 +25,3 @@ func StartApp() { stopapp.GetWaitGroup_Main().Wait() } - diff --git a/examples/rapira/templates/configs_/model_crud_delete_functions.json b/examples/rapira/templates/configs_/model_crud_delete_functions.json new file mode 100644 index 0000000..6a8d05d --- /dev/null +++ b/examples/rapira/templates/configs_/model_crud_delete_functions.json @@ -0,0 +1,3 @@ +{ + "lawsuits": "NewLawsuit,AsLawsuit" +} diff --git a/examples/rapira/templates/configs_/nullable.json b/examples/rapira/templates/configs_/nullable.json index 1e5062a..3f0a502 100644 --- a/examples/rapira/templates/configs_/nullable.json +++ b/examples/rapira/templates/configs_/nullable.json @@ -1,4 +1,4 @@ { - "ExtID": true, - "CreatedAt": false + "ext_id": true, + "created_at": false } diff --git a/examples/rapira/templates/configs_/readme.txt b/examples/rapira/templates/configs_/readme.txt index ce1442e..1c44590 100644 --- a/examples/rapira/templates/configs_/readme.txt +++ b/examples/rapira/templates/configs_/readme.txt @@ -1,21 +1,47 @@ convert_id.json: Mapping database table name . field name = field type in golang. -For model file. +For tables file. For non standart rare case or type aliases +example: +{ + "lawsuit_payments.id": "alias.PaymentId", + "lawsuit_payments.invoice_id": "alias.InvoiceId", +} + mapping.json Mapping Postgres types to Golang types + name_replace.json Mapping database field name = golang field name -For model file. +For tables file. Replace standart field name to filled name For non standart rare case. +example: +{ + "inn": "INN", + "json_file_id": "JSONFileID" +} nullable.json List of golang field names, which need change 0 to null. true = need change 0 to null For non standart rare case. +example: +{ + "ext_id": true, + "created_at": false +} + + +model_crud_delete_functions.json +Mapping postgres tables to golang function name, +this functions will be deleted from model crud files. +example: +{ + "lawsuits": "NewLawsuit,AsLawsuit" +} diff --git a/examples/rapira/templates/configs_/settings.txt b/examples/rapira/templates/configs_/settings.txt index 41846ac..6647da1 100644 --- a/examples/rapira/templates/configs_/settings.txt +++ b/examples/rapira/templates/configs_/settings.txt @@ -1,21 +1,21 @@ #---------------------Database settings--------------------- #DB_HOST - Database server name or ip-address. Only Postgres SQL -DB_HOST="" +DB_HOST= #DB_NAME - Database table name -DB_NAME="" +DB_NAME= #DB_SCHEME - Database schema name -DB_SCHEME="" +DB_SCHEME= #DB_PORT - Database port number -DB_PORT="" +DB_PORT= #DB_USER - Database login (user) -DB_USER="" +DB_USER= #DB_PASSWORD - Database login password -DB_PASSWORD="" +DB_PASSWORD= #INCLUDE_TABLES - table name filter. Regular expression INCLUDE_TABLES="" @@ -53,12 +53,11 @@ TEMPLATE_FOLDERNAME_CRUD="pkg/db/crud" #TEMPLATE_FOLDERNAME_TABLES - folder name for create database tables models TEMPLATE_FOLDERNAME_TABLES="pkg/db/tables" -#TEMPLATE_FOLDERNAME_DB - folder name for create db constants +#TEMPLATE_FOLDERNAME_DB - folder name for create db TEMPLATE_FOLDERNAME_DB="pkg/db" - #TEMPLATE_FOLDERNAME_GRPC - folder name for create .proto file -TEMPLATE_FOLDERNAME_GRPC_PROTO="pkg/network/grpc" +TEMPLATE_FOLDERNAME_GRPC_PROTO="api" #TEMPLATE_FOLDERNAME_GRPC - folder name for grpc TEMPLATE_FOLDERNAME_GRPC="pkg/network/grpc" @@ -84,6 +83,9 @@ TEMPLATE_FOLDERNAME_CRUD_STARTER="pkg/crud_starter" #TEMPLATE_FOLDERNAME_ALIAS - folder name for create alias.go file, with go types with aliases TEMPLATE_FOLDERNAME_ALIAS="pkg/object_model/types/alias" +#TEMPLATE_FOLDER_CRUD_FUNCTIONS - folder name for create crud_functions.go file +TEMPLATE_FOLDER_CRUD_FUNCTIONS="pkg/db/crud_functions" + #TEXT_TEMPLATE_MODEL - model name text in templates, for replace to new model names TEXT_TEMPLATE_MODEL="LawsuitStatusType" diff --git a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc.go_ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc.go_ index 3fd91d3..b0de569 100644 --- a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc.go_ +++ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc.go_ @@ -281,4 +281,3 @@ func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request return &Otvet, err } - diff --git a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ index f964de6..41f5bd7 100644 --- a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ +++ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ @@ -3,7 +3,7 @@ package server_grpc import ( "errors" "github.com/ManyakRus/starter/micro" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/constants" ) // ErrorModelVersion diff --git a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_starter.go_ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_starter.go_ index 0f0b134..19b0814 100644 --- a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_starter.go_ +++ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_starter.go_ @@ -92,4 +92,3 @@ func Start() { func CloseConnection() { Conn.Stop() } - diff --git a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ index edcc42c..b44b962 100644 --- a/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ +++ b/examples/rapira/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ @@ -190,4 +190,3 @@ func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) { t.Error("Test_server_LawsuitStatusType_FindByExtId() error: ModelString=''") } } - diff --git a/examples/rapira/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ b/examples/rapira/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ index 4aa582f..f5b4fd0 100644 --- a/examples/rapira/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ +++ b/examples/rapira/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ @@ -5,12 +5,17 @@ import ( "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/stopapp" "github.com/nats-io/nats.go" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/internal/app/grpc/server_grpc" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "os" + "strings" "time" ) +//// server is used to implement UnimplementedSyncServiceServer. +//type server struct { +//} + type SettingsINI struct { NATS_HOST string NATS_PORT string @@ -77,6 +82,14 @@ func FillSettings() { Settings.NATS_PORT = os.Getenv("BUS_LOCAL_PORT") } + //удалим лишний :порт + if Settings.NATS_PORT != "" { + pos1 := strings.Index(Settings.NATS_HOST, ":") + if pos1 > 0 { + Settings.NATS_HOST = Settings.NATS_HOST[0:pos1] + } + } + //проверка if Settings.NATS_HOST == "" { log.Panic("Need fill BUS_LOCAL_HOST ! in OS Environment ") @@ -89,6 +102,7 @@ func FillSettings() { // WaitStop - ожидает отмену глобального контекста func WaitStop() { + defer stopapp.GetWaitGroup_Main().Done() select { case <-contextmain.GetContext().Done(): @@ -100,7 +114,7 @@ func WaitStop() { //закрываем соединение CloseConnection() - stopapp.GetWaitGroup_Main().Done() + } // Start - необходимые процедуры для запуска сервера GRPC diff --git a/examples/rapira/templates/pkg/db/constants/constants.go b/examples/rapira/templates/pkg/db/constants/constants.go index d8a63a6..d1deba6 100644 --- a/examples/rapira/templates/pkg/db/constants/constants.go +++ b/examples/rapira/templates/pkg/db/constants/constants.go @@ -1,7 +1,15 @@ package constants +import ( + "errors" +) + const CONNECTION_ID_TEST = 3 const TIMEOUT_DB_SECONDS = 30 const TEXT_RECORD_NOT_FOUND = "record not found" + +const TextCrudIsNotInit = "Need initializate crud with InitCrudTransport_NRPC() function at first." + +var ErrorCrudIsNotInit error = errors.New(TextCrudIsNotInit) diff --git a/examples/rapira/templates/pkg/db/crud/crud.go_ b/examples/rapira/templates/pkg/db/crud/crud.go_ index 4d958b9..c4fe2cd 100644 --- a/examples/rapira/templates/pkg/db/crud/crud.go_ +++ b/examples/rapira/templates/pkg/db/crud/crud.go_ @@ -8,9 +8,9 @@ import ( "github.com/ManyakRus/starter/postgres_gorm" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" - "gorm.io/gorm" "time" "github.com/ManyakRus/starter/contextmain" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud_functions" ) // TableName - имя таблицы в БД Postgres @@ -170,7 +170,6 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ MassOmit := make([]string, 0) var ColumnName string - //игнор пустых колонок tx = tx.Omit(MassOmit...) @@ -185,18 +184,14 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ return err } - // запишем NULL в пустые колонки - for f := 0; f < len(MassOmit); f++ { - ColumnName := MassOmit[f] - tx = db.Model(&m).Update(ColumnName, gorm.Expr("NULL")) - - err = tx.Error - if err != nil { - TextError := fmt.Sprint("db.Update() ", TableName, " id: ", m.ID, " error: ", err) - err = errors.New(TextError) - return err - // log.Panic(sError) - } + //запишем NULL в пустые колонки + MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit) + tx = db.Model(&m).Updates(MapOmit) + err = tx.Error + if err != nil { + TextError := fmt.Sprint("Updates() ", TableName, " id: ", m.ID, " error: ", err) + err = errors.New(TextError) + return err } return err diff --git a/examples/rapira/templates/pkg/db/crud_functions/crud_functions.go b/examples/rapira/templates/pkg/db/crud_functions/crud_functions.go new file mode 100644 index 0000000..880d9f0 --- /dev/null +++ b/examples/rapira/templates/pkg/db/crud_functions/crud_functions.go @@ -0,0 +1,13 @@ +package crud_functions + +import "gorm.io/gorm" + +// MapOmit_from_MassOmit - создает MapOmit из MassOmit +func MapOmit_from_MassOmit(MassOmit []string) map[string]interface{} { + MapOmit := make(map[string]interface{}, 0) + for _, v := range MassOmit { + MapOmit[v] = gorm.Expr("NULL") + } + + return MapOmit +} diff --git a/examples/rapira/templates/pkg/db/crud_functions/crud_functions_test.go b/examples/rapira/templates/pkg/db/crud_functions/crud_functions_test.go new file mode 100644 index 0000000..31a80a7 --- /dev/null +++ b/examples/rapira/templates/pkg/db/crud_functions/crud_functions_test.go @@ -0,0 +1 @@ +package crud_functions diff --git a/examples/rapira/templates/pkg/db/tables/table.go_ b/examples/rapira/templates/pkg/db/tables/table.go_ index 7a2ccfc..b5c4ead 100644 --- a/examples/rapira/templates/pkg/db/tables/table.go_ +++ b/examples/rapira/templates/pkg/db/tables/table.go_ @@ -10,4 +10,3 @@ type LawsuitStatusType struct { tables.NameStruct Code string `json:"code" gorm:"column:code;default:0"` } - diff --git a/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ b/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ index 9c298e2..5cfc11c 100644 --- a/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ +++ b/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ @@ -319,4 +319,3 @@ func (crud Crud_GRPC) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) er return err } - diff --git a/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ b/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ index cf7637d..2bd2c6d 100644 --- a/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ +++ b/examples/rapira/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ @@ -182,4 +182,3 @@ func TestFindByExtID(t *testing.T) { t.Error("TestFindByExtID() error: ID =0") } } - diff --git a/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ b/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ index cbdc28a..11c56af 100644 --- a/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ +++ b/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ @@ -289,4 +289,3 @@ func (crud Crud_NRPC) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) er return err } - diff --git a/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_ b/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_ index 74d2d14..8e58f6a 100644 --- a/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_ +++ b/examples/rapira/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_ @@ -182,4 +182,3 @@ func TestFindByExtID(t *testing.T) { t.Error("TestFindByExtId() error: ID =0") } } - diff --git a/examples/rapira/templates/pkg/object_model/entities/model.go_ b/examples/rapira/templates/pkg/object_model/entities/model.go_ index 0af29b3..75d8282 100644 --- a/examples/rapira/templates/pkg/object_model/entities/model.go_ +++ b/examples/rapira/templates/pkg/object_model/entities/model.go_ @@ -8,4 +8,3 @@ import ( type LawsuitStatusType struct { table_lawsuit_status_types.Table_LawsuitStatusType } - diff --git a/examples/rapira/templates/pkg/object_model/entities/model_crud.go_ b/examples/rapira/templates/pkg/object_model/entities/model_crud.go_ index fb563b4..d00a2b5 100644 --- a/examples/rapira/templates/pkg/object_model/entities/model_crud.go_ +++ b/examples/rapira/templates/pkg/object_model/entities/model_crud.go_ @@ -5,6 +5,7 @@ import ( "github.com/vmihailenco/msgpack/v5" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/calc_struct_version" "reflect" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" ) // versionLawsuitStatusType - версия структуры модели, с учётом имен и типов полей @@ -91,6 +92,10 @@ func (m LawsuitStatusType) GetJSON() (string, error) { // Read - находит запись в БД по ID, и заполняет в объект func (m *LawsuitStatusType) Read() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Read(m) return err @@ -98,6 +103,10 @@ func (m *LawsuitStatusType) Read() error { // Save - записывает объект в БД по ID func (m *LawsuitStatusType) Save() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Save(m) return err @@ -105,6 +114,10 @@ func (m *LawsuitStatusType) Save() error { // Update - обновляет объект в БД по ID func (m *LawsuitStatusType) Update() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Update(m) return err @@ -112,6 +125,10 @@ func (m *LawsuitStatusType) Update() error { // Create - создаёт объект в БД с новым ID func (m *LawsuitStatusType) Create() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Create(m) return err @@ -119,6 +136,10 @@ func (m *LawsuitStatusType) Create() error { // Delete - устанавливает признак пометки удаления в БД func (m *LawsuitStatusType) Delete() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Delete(m) return err @@ -126,6 +147,10 @@ func (m *LawsuitStatusType) Delete() error { // Restore - снимает признак пометки удаления в БД func (m *LawsuitStatusType) Restore() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Restore(m) return err @@ -133,6 +158,10 @@ func (m *LawsuitStatusType) Restore() error { // Find_ByExtID - находит объект по ExtID func (m *LawsuitStatusType) Find_ByExtID() error { + if crud_LawsuitStatusType == nil { + return constants.ErrorCrudIsNotInit + } + err := crud_LawsuitStatusType.Find_ByExtID(m) return err