mirror of https://github.com/go-gorm/gorm.git
Setup DB's ConnPool in PrepareStmt mode, fix #3362
This commit is contained in:
parent
ff3880292d
commit
98e15e0b95
2
gorm.go
2
gorm.go
|
@ -176,6 +176,8 @@ func (db *DB) Session(config *Session) *DB {
|
||||||
Mux: preparedStmt.Mux,
|
Mux: preparedStmt.Mux,
|
||||||
Stmts: preparedStmt.Stmts,
|
Stmts: preparedStmt.Stmts,
|
||||||
}
|
}
|
||||||
|
txConfig.ConnPool = tx.Statement.ConnPool
|
||||||
|
txConfig.PrepareStmt = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ import (
|
||||||
func TestPreparedStmt(t *testing.T) {
|
func TestPreparedStmt(t *testing.T) {
|
||||||
tx := DB.Session(&gorm.Session{PrepareStmt: true})
|
tx := DB.Session(&gorm.Session{PrepareStmt: true})
|
||||||
|
|
||||||
|
if _, ok := tx.ConnPool.(*gorm.PreparedStmtDB); !ok {
|
||||||
|
t.Fatalf("should assign PreparedStatement Manager back to database when using PrepareStmt mode")
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
txCtx := tx.WithContext(ctx)
|
txCtx := tx.WithContext(ctx)
|
||||||
|
|
Loading…
Reference in New Issue