pgxtrace

package module
v0.0.0-...-7623478 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 2 Imported by: 2

README

pgxtrace

A trace package for pgx

Go Reference

Getting Started

You can use these examples to get started.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeQueryTracer

type CompositeQueryTracer []pgx.QueryTracer

CompositeQueryTracer represent a composite query tracer

Example
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL"))
if err != nil {
	panic(err)
}

config.ConnConfig.Tracer = pgxtrace.CompositeQueryTracer{}

conn, err := pgxpool.NewWithConfig(context.TODO(), config)
if err != nil {
	panic(err)
}
defer conn.Close()

rows, err := conn.Query(context.TODO(), "SELECT * from customer")
if err != nil {
	panic(err)
}
// close the rows
defer rows.Close()

// Customer struct must be defined
type Customer struct {
	FirstName string `db:"first_name"`
	LastName  string `db:"last_name"`
}

for rows.Next() {
	customer, err := pgx.RowToStructByName[Customer](rows)
	if err != nil {
		panic(err)
	}

	fmt.Println(customer.FirstName)
}
Output:

func (CompositeQueryTracer) TraceBatchEnd

func (t CompositeQueryTracer) TraceBatchEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchEndData)

TraceBatchEnd implements pgx.BatchTracer.

func (CompositeQueryTracer) TraceBatchQuery

func (t CompositeQueryTracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)

TraceBatchQuery implements pgx.BatchTracer.

func (CompositeQueryTracer) TraceBatchStart

func (t CompositeQueryTracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context

TraceBatchStart implements pgx.BatchTracer.

func (CompositeQueryTracer) TraceConnectEnd

func (t CompositeQueryTracer) TraceConnectEnd(ctx context.Context, data pgx.TraceConnectEndData)

TraceConnectEnd implements pgx.ConnectTracer.

func (CompositeQueryTracer) TraceConnectStart

func (t CompositeQueryTracer) TraceConnectStart(ctx context.Context, data pgx.TraceConnectStartData) context.Context

TraceConnectStart implements pgx.ConnectTracer.

func (CompositeQueryTracer) TraceCopyFromEnd

func (t CompositeQueryTracer) TraceCopyFromEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromEndData)

TraceCopyFromEnd implements pgx.CopyFromTracer.

func (CompositeQueryTracer) TraceCopyFromStart

func (t CompositeQueryTracer) TraceCopyFromStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context

TraceCopyFromStart implements pgx.CopyFromTracer.

func (CompositeQueryTracer) TracePrepareEnd

func (t CompositeQueryTracer) TracePrepareEnd(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareEndData)

TracePrepareEnd implements pgx.PrepareTracer.

func (CompositeQueryTracer) TracePrepareStart

func (t CompositeQueryTracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context

TracePrepareStart implements pgx.PrepareTracer.

func (CompositeQueryTracer) TraceQueryEnd

func (t CompositeQueryTracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData)

TraceQueryEnd implements pgx.QueryTracer.

func (CompositeQueryTracer) TraceQueryStart

func (t CompositeQueryTracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context

TraceQueryStart implements pgx.QueryTracer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL