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)) +}