mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал RawMultipleSQL()
This commit is contained in:
2
Makefile
2
Makefile
@@ -47,3 +47,5 @@ conn:
|
||||
lines:
|
||||
clear
|
||||
go_lines_count ./ ./docs/lines_count.txt 10
|
||||
licenses:
|
||||
golicense -out-xlsx=./docs/licenses.xlsx $(FILEAPP)
|
||||
|
||||
@@ -440,6 +440,11 @@ func RawMultipleSQL(db *gorm.DB, TextSQL string) *gorm.DB {
|
||||
return tx
|
||||
}
|
||||
|
||||
//запустим транзакцию
|
||||
tx.Begin()
|
||||
defer tx.Commit()
|
||||
|
||||
//
|
||||
TextSQL1 := ""
|
||||
TextSQL2 := TextSQL
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user