sqlmw icon indicating copy to clipboard operation
sqlmw copied to clipboard

feat(context): export wrapped parent struct and add stmt context

Open Just-maple opened this issue 1 year ago • 0 comments

  1. 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 ... 
      ...
}
  1. 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 ... 
      ...
}

Just-maple avatar May 12 '23 04:05 Just-maple