...

Source file src/github.com/jackc/pgx/v5/tracer.go

Documentation: github.com/jackc/pgx/v5

     1  package pgx
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/jackc/pgx/v5/pgconn"
     7  )
     8  
     9  // QueryTracer traces Query, QueryRow, and Exec.
    10  type QueryTracer interface {
    11  	// TraceQueryStart is called at the beginning of Query, QueryRow, and Exec calls. The returned context is used for the
    12  	// rest of the call and will be passed to TraceQueryEnd.
    13  	TraceQueryStart(ctx context.Context, conn *Conn, data TraceQueryStartData) context.Context
    14  
    15  	TraceQueryEnd(ctx context.Context, conn *Conn, data TraceQueryEndData)
    16  }
    17  
    18  type TraceQueryStartData struct {
    19  	SQL  string
    20  	Args []any
    21  }
    22  
    23  type TraceQueryEndData struct {
    24  	CommandTag pgconn.CommandTag
    25  	Err        error
    26  }
    27  
    28  // BatchTracer traces SendBatch.
    29  type BatchTracer interface {
    30  	// TraceBatchStart is called at the beginning of SendBatch calls. The returned context is used for the
    31  	// rest of the call and will be passed to TraceBatchQuery and TraceBatchEnd.
    32  	TraceBatchStart(ctx context.Context, conn *Conn, data TraceBatchStartData) context.Context
    33  
    34  	TraceBatchQuery(ctx context.Context, conn *Conn, data TraceBatchQueryData)
    35  	TraceBatchEnd(ctx context.Context, conn *Conn, data TraceBatchEndData)
    36  }
    37  
    38  type TraceBatchStartData struct {
    39  	Batch *Batch
    40  }
    41  
    42  type TraceBatchQueryData struct {
    43  	SQL        string
    44  	Args       []any
    45  	CommandTag pgconn.CommandTag
    46  	Err        error
    47  }
    48  
    49  type TraceBatchEndData struct {
    50  	Err error
    51  }
    52  
    53  // CopyFromTracer traces CopyFrom.
    54  type CopyFromTracer interface {
    55  	// TraceCopyFromStart is called at the beginning of CopyFrom calls. The returned context is used for the
    56  	// rest of the call and will be passed to TraceCopyFromEnd.
    57  	TraceCopyFromStart(ctx context.Context, conn *Conn, data TraceCopyFromStartData) context.Context
    58  
    59  	TraceCopyFromEnd(ctx context.Context, conn *Conn, data TraceCopyFromEndData)
    60  }
    61  
    62  type TraceCopyFromStartData struct {
    63  	TableName   Identifier
    64  	ColumnNames []string
    65  }
    66  
    67  type TraceCopyFromEndData struct {
    68  	CommandTag pgconn.CommandTag
    69  	Err        error
    70  }
    71  
    72  // PrepareTracer traces Prepare.
    73  type PrepareTracer interface {
    74  	// TracePrepareStart is called at the beginning of Prepare calls. The returned context is used for the
    75  	// rest of the call and will be passed to TracePrepareEnd.
    76  	TracePrepareStart(ctx context.Context, conn *Conn, data TracePrepareStartData) context.Context
    77  
    78  	TracePrepareEnd(ctx context.Context, conn *Conn, data TracePrepareEndData)
    79  }
    80  
    81  type TracePrepareStartData struct {
    82  	Name string
    83  	SQL  string
    84  }
    85  
    86  type TracePrepareEndData struct {
    87  	AlreadyPrepared bool
    88  	Err             error
    89  }
    90  
    91  // ConnectTracer traces Connect and ConnectConfig.
    92  type ConnectTracer interface {
    93  	// TraceConnectStart is called at the beginning of Connect and ConnectConfig calls. The returned context is used for
    94  	// the rest of the call and will be passed to TraceConnectEnd.
    95  	TraceConnectStart(ctx context.Context, data TraceConnectStartData) context.Context
    96  
    97  	TraceConnectEnd(ctx context.Context, data TraceConnectEndData)
    98  }
    99  
   100  type TraceConnectStartData struct {
   101  	ConnConfig *ConnConfig
   102  }
   103  
   104  type TraceConnectEndData struct {
   105  	Conn *Conn
   106  	Err  error
   107  }
   108  

View as plain text