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, | ||||
| 				Stmts:    preparedStmt.Stmts, | ||||
| 			} | ||||
| 			txConfig.ConnPool = tx.Statement.ConnPool | ||||
| 			txConfig.PrepareStmt = true | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -12,6 +12,10 @@ import ( | ||||
| func TestPreparedStmt(t *testing.T) { | ||||
| 	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) | ||||
| 	defer cancel() | ||||
| 	txCtx := tx.WithContext(ctx) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu