From efa1ece363baf725dfea3583ce488fd51c75f7ac Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Fri, 22 Mar 2024 08:54:12 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20RawMulti?= =?UTF-8?q?pleSQL()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 ++ postgres_gorm/postgres_gorm.go | 5 ++++ postgres_gorm/postgres_gorm_test.go | 41 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/Makefile b/Makefile index 62767920..aa1ec215 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,5 @@ conn: lines: clear go_lines_count ./ ./docs/lines_count.txt 10 +licenses: + golicense -out-xlsx=./docs/licenses.xlsx $(FILEAPP) diff --git a/postgres_gorm/postgres_gorm.go b/postgres_gorm/postgres_gorm.go index eabe4483..9418e02d 100644 --- a/postgres_gorm/postgres_gorm.go +++ b/postgres_gorm/postgres_gorm.go @@ -440,6 +440,11 @@ func RawMultipleSQL(db *gorm.DB, TextSQL string) *gorm.DB { return tx } + //запустим транзакцию + tx.Begin() + defer tx.Commit() + + // TextSQL1 := "" TextSQL2 := TextSQL diff --git a/postgres_gorm/postgres_gorm_test.go b/postgres_gorm/postgres_gorm_test.go index 9e4b10ad..2ea900b2 100644 --- a/postgres_gorm/postgres_gorm_test.go +++ b/postgres_gorm/postgres_gorm_test.go @@ -175,3 +175,44 @@ SELECT * FROM temp_TestRawMultipleSQL2 t.Log("Прошло время: ", time.Since(TimeStart)) } + +func TestRawMultipleSQL3(t *testing.T) { + config_main.LoadEnv() + GetConnection() + defer CloseConnection() + + TimeStart := time.Now() + + TextSQL := ` +drop table if exists temp_TestRawMultipleSQL2; +CREATE TEMPORARY TABLE temp_TestRawMultipleSQL2 (id int); + +insert into temp_TestRawMultipleSQL2 +select 1; + +SELECT * FROM temp_TestRawMultipleSQL2 +` + f := func(t *testing.T) { + tx := RawMultipleSQL(Conn, TextSQL) + err := tx.Error + if err != nil { + t.Error("TestRawMultipleSQL3() error: ", err) + } + + if tx.RowsAffected != 1 { + t.Error("TestRawMultipleSQL3() RowsAffected = ", tx.RowsAffected) + } + + } + + //запустим 100 потоков + for i := 0; i < 100; i++ { + stopapp.GetWaitGroup_Main().Add(1) + go f(t) + stopapp.GetWaitGroup_Main().Done() + } + + stopapp.GetWaitGroup_Main().Wait() + + t.Log("Прошло время: ", time.Since(TimeStart)) +}