@@ -17,6 +17,9 @@ type hooks interface {
17
17
preOpen (c context.Context , name string ) (interface {}, error )
18
18
open (c context.Context , ctx interface {}, conn * Conn ) error
19
19
postOpen (c context.Context , ctx interface {}, conn * Conn , err error ) error
20
+ prePrepare (c context.Context , stmt * Stmt ) (interface {}, error )
21
+ prepare (c context.Context , ctx interface {}, stmt * Stmt ) error
22
+ postPrepare (c context.Context , ctx interface {}, stmt * Stmt , err error ) error
20
23
preExec (c context.Context , stmt * Stmt , args []driver.NamedValue ) (interface {}, error )
21
24
exec (c context.Context , ctx interface {}, stmt * Stmt , args []driver.NamedValue , result driver.Result ) error
22
25
postExec (c context.Context , ctx interface {}, stmt * Stmt , args []driver.NamedValue , result driver.Result , err error ) error
@@ -109,6 +112,36 @@ type HooksContext struct {
109
112
// `Hooks.PreOpen` method, and may be nil.
110
113
PostOpen func (c context.Context , ctx interface {}, conn * Conn , err error ) error
111
114
115
+ // PrePrepare is a callback that gets called prior to calling
116
+ // `db.Prepare`, and is ALWAYS called. If this callback returns an
117
+ // error, the underlying driver's `db.Exec` and `Hooks.Prepare` methods
118
+ // are not called.
119
+ //
120
+ // The first return value is passed to both `Hooks.Prepare` and
121
+ // `Hooks.PostPrepare` callbacks. You may specify anything you want.
122
+ // Return nil if you do not need to use it.
123
+ //
124
+ // The second return value is indicates the error found while
125
+ // executing this hook.
126
+ PrePrepare func (c context.Context , stmt * Stmt ) (interface {}, error )
127
+
128
+ // Prepare is called after the underlying driver's `db.Prepare` method
129
+ // returns without any errors.
130
+ //
131
+ // The `ctx` parameter is the return value supplied from the
132
+ // `Hooks.PrePrepare` method, and may be nil.
133
+ //
134
+ // If this callback returns an error, then the error from this
135
+ // callback is returned by the `db.Prepare` method.
136
+ Prepare func (c context.Context , ctx interface {}, stmt * Stmt ) error
137
+
138
+ // PostPrepare is a callback that gets called at the end of
139
+ // the call to `db.Prepare`. It is ALWAYS called.
140
+ //
141
+ // The `ctx` parameter is the return value supplied from the
142
+ // `Hooks.PrePrepare` method, and may be nil.
143
+ PostPrepare func (c context.Context , ctx interface {}, stmt * Stmt , err error ) error
144
+
112
145
// PreExec is a callback that gets called prior to calling
113
146
// `Stmt.Exec`, and is ALWAYS called. If this callback returns an
114
147
// error, the underlying driver's `Stmt.Exec` and `Hooks.Exec` methods
@@ -405,6 +438,27 @@ func (h *HooksContext) postOpen(c context.Context, ctx interface{}, conn *Conn,
405
438
return h .PostOpen (c , ctx , conn , err )
406
439
}
407
440
441
+ func (h * HooksContext ) prePrepare (c context.Context , stmt * Stmt ) (interface {}, error ) {
442
+ if h == nil || h .PrePrepare == nil {
443
+ return nil , nil
444
+ }
445
+ return h .PrePrepare (c , stmt )
446
+ }
447
+
448
+ func (h * HooksContext ) prepare (c context.Context , ctx interface {}, stmt * Stmt ) error {
449
+ if h == nil || h .Prepare == nil {
450
+ return nil
451
+ }
452
+ return h .Prepare (c , ctx , stmt )
453
+ }
454
+
455
+ func (h * HooksContext ) postPrepare (c context.Context , ctx interface {}, stmt * Stmt , err error ) error {
456
+ if h == nil || h .PostPrepare == nil {
457
+ return nil
458
+ }
459
+ return h .PostPrepare (c , ctx , stmt , err )
460
+ }
461
+
408
462
func (h * HooksContext ) preExec (c context.Context , stmt * Stmt , args []driver.NamedValue ) (interface {}, error ) {
409
463
if h == nil || h .PreExec == nil {
410
464
return nil , nil
@@ -929,6 +983,18 @@ func (h *Hooks) postOpen(c context.Context, ctx interface{}, conn *Conn, err err
929
983
return h .PostOpen (ctx , conn )
930
984
}
931
985
986
+ func (h * Hooks ) prePrepare (c context.Context , stmt * Stmt ) (interface {}, error ) {
987
+ return nil , nil
988
+ }
989
+
990
+ func (h * Hooks ) prepare (c context.Context , ctx interface {}, stmt * Stmt ) error {
991
+ return nil
992
+ }
993
+
994
+ func (h * Hooks ) postPrepare (c context.Context , ctx interface {}, stmt * Stmt , err error ) error {
995
+ return nil
996
+ }
997
+
932
998
func (h * Hooks ) preExec (c context.Context , stmt * Stmt , args []driver.NamedValue ) (interface {}, error ) {
933
999
if h == nil || h .PreExec == nil {
934
1000
return nil , nil
@@ -1187,6 +1253,24 @@ func (h multipleHooks) postOpen(c context.Context, ctx interface{}, conn *Conn,
1187
1253
})
1188
1254
}
1189
1255
1256
+ func (h multipleHooks ) prePrepare (c context.Context , stmt * Stmt ) (interface {}, error ) {
1257
+ return h .preDo (func (h hooks ) (interface {}, error ) {
1258
+ return h .prePrepare (c , stmt )
1259
+ })
1260
+ }
1261
+
1262
+ func (h multipleHooks ) prepare (c context.Context , ctx interface {}, stmt * Stmt ) error {
1263
+ return h .do (ctx , func (h hooks , ctx interface {}) error {
1264
+ return h .prepare (c , ctx , stmt )
1265
+ })
1266
+ }
1267
+
1268
+ func (h multipleHooks ) postPrepare (c context.Context , ctx interface {}, stmt * Stmt , err error ) error {
1269
+ return h .postDo (ctx , err , func (h hooks , ctx interface {}, err error ) error {
1270
+ return h .postPrepare (c , ctx , stmt , err )
1271
+ })
1272
+ }
1273
+
1190
1274
func (h multipleHooks ) preExec (c context.Context , stmt * Stmt , args []driver.NamedValue ) (interface {}, error ) {
1191
1275
return h .preDo (func (h hooks ) (interface {}, error ) {
1192
1276
return h .preExec (c , stmt , args )
0 commit comments