sqlmw
sqlmw copied to clipboard
feat(context): export wrapped parent struct and add stmt context
- export
WrappedParentXXX
like Struct
So that users can use
func (Interceptor)ConnExecContext(ctx context.Context, conn driver.ExecerContext, s string, values []driver.NamedValue) (ret driver.Result, err error) {
// sqlmw wrapped
wpConn,ok := conn.(WrappedParentConn)
if ok{
// user wrapped connection
if myconn,ok := wpConn.Conn.(MyConn);ok{
connectInfo := myconn.Info()
}
}
// use my connect info to do log / trace / metrics / telemetry ...
...
}
- Add Stmt WrappedParent Context in Stmt Execute and Query
func (Interceptor)StmtQueryContext(ctx context.Context, queryer driver.StmtQueryContext, s string, values []driver.NamedValue) (nctx context.Context, rows driver.Rows, err error) { {
// sqlmw wrapped
wpStmt,ok := conn.(WrappedParentStmt)
if ok{
parentCtx := wpStmt.Context()
}
// use parent context info to do log / trace / metrics / telemetry ...
...
}