github.com/RevenueMonster/sqlike@v1.0.6/plugin/opentracing/result.go (about)

     1  package opentracing
     2  
     3  import (
     4  	"context"
     5  	"database/sql/driver"
     6  
     7  	"github.com/opentracing/opentracing-go/log"
     8  )
     9  
    10  // ResultLastInsertId :
    11  func (ot *OpenTracingInterceptor) ResultLastInsertId(ctx context.Context, result driver.Result) (id int64, err error) {
    12  	if ot.opts.LastInsertID {
    13  		span, _ := ot.MaybeStartSpanFromContext(ctx, "last_insert_id")
    14  		span.LogFields(
    15  			log.Int64("last_insert_id", id),
    16  		)
    17  		defer func() {
    18  			ot.logError(span, err)
    19  			span.Finish()
    20  		}()
    21  	}
    22  	id, err = result.LastInsertId()
    23  	return
    24  }
    25  
    26  // ResultRowsAffected :
    27  func (ot *OpenTracingInterceptor) ResultRowsAffected(ctx context.Context, result driver.Result) (affected int64, err error) {
    28  	if ot.opts.RowsAffected {
    29  		span, _ := ot.MaybeStartSpanFromContext(ctx, "rows_affected")
    30  		span.LogFields(
    31  			log.Int64("rows_affected", affected),
    32  		)
    33  		defer func() {
    34  			ot.logError(span, err)
    35  			span.Finish()
    36  		}()
    37  	}
    38  	affected, err = result.RowsAffected()
    39  	return
    40  }