@@ -187,15 +187,9 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
187
187
}
188
188
}
189
189
190
- preparedStmt := & PreparedStmtDB {
191
- ConnPool : db .ConnPool ,
192
- Stmts : make (map [string ]* Stmt ),
193
- Mux : & sync.RWMutex {},
194
- PreparedSQL : make ([]string , 0 , 100 ),
195
- }
196
- db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
197
-
198
190
if config .PrepareStmt {
191
+ preparedStmt := NewPreparedStmtDB (db .ConnPool )
192
+ db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
199
193
db .ConnPool = preparedStmt
200
194
}
201
195
@@ -256,24 +250,30 @@ func (db *DB) Session(config *Session) *DB {
256
250
}
257
251
258
252
if config .PrepareStmt {
253
+ var preparedStmt * PreparedStmtDB
254
+
259
255
if v , ok := db .cacheStore .Load (preparedStmtDBKey ); ok {
260
- preparedStmt := v .(* PreparedStmtDB )
261
- switch t := tx .Statement .ConnPool .(type ) {
262
- case Tx :
263
- tx .Statement .ConnPool = & PreparedStmtTX {
264
- Tx : t ,
265
- PreparedStmtDB : preparedStmt ,
266
- }
267
- default :
268
- tx .Statement .ConnPool = & PreparedStmtDB {
269
- ConnPool : db .Config .ConnPool ,
270
- Mux : preparedStmt .Mux ,
271
- Stmts : preparedStmt .Stmts ,
272
- }
256
+ preparedStmt = v .(* PreparedStmtDB )
257
+ } else {
258
+ preparedStmt = NewPreparedStmtDB (db .ConnPool )
259
+ db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
260
+ }
261
+
262
+ switch t := tx .Statement .ConnPool .(type ) {
263
+ case Tx :
264
+ tx .Statement .ConnPool = & PreparedStmtTX {
265
+ Tx : t ,
266
+ PreparedStmtDB : preparedStmt ,
267
+ }
268
+ default :
269
+ tx .Statement .ConnPool = & PreparedStmtDB {
270
+ ConnPool : db .Config .ConnPool ,
271
+ Mux : preparedStmt .Mux ,
272
+ Stmts : preparedStmt .Stmts ,
273
273
}
274
- txConfig .ConnPool = tx .Statement .ConnPool
275
- txConfig .PrepareStmt = true
276
274
}
275
+ txConfig .ConnPool = tx .Statement .ConnPool
276
+ txConfig .PrepareStmt = true
277
277
}
278
278
279
279
if config .SkipHooks {
0 commit comments