sqldb

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

WILL BE DEPRECATED WHEN TRACING IS MOVED TO A SEPARATE PACAKGE THIS IS HERE TO AVOID CIRCULAR DEPENDENCIES

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Begin() (*Tx, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
	Close() error
	Conn(ctx context.Context) (*sql.Conn, error)
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Ping() error
	PingContext(ctx context.Context) error
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	SetConnMaxIdleTime(d time.Duration)
	SetConnMaxLifetime(d time.Duration)
	Stats() sql.DBStats
	WithHook(h Hook)
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
}

func DBWarpper added in v0.3.6

func DBWarpper(
	db *sql.DB,
	t Trx,
	name string,
	logger *zap.Logger,
) DB

DBWarpper() returns the underlying DB wrapping the driver

func New added in v0.4.5

func New(Driver string, DSN string) DB

New returns a NativeDatabase interface for the given driver and DSN WARNING: It will panic if the driver is not supported

func NewWithOptions added in v0.4.5

func NewWithOptions(Driver string, DSN string, opts *Options) DB

New returns a NativeDatabase interface for the given driver and DSN WARNING: It will panic if the driver is not supported

func TracedNativeDBWrapper

func TracedNativeDBWrapper(
	Driver string,
	DSN string,
	t Trx,
	name string,
) DB

TracedNativeDBWrapper returns a DB interface for the given driver and DSN WARNING: It will panic if the driver is not supported DEPRECATED: Use New Or NewWithOptions instead

func TracedNativeDBWrapperWithOptions added in v0.4.1

func TracedNativeDBWrapperWithOptions(
	Driver string,
	DSN string,
	t *tracer.AppInsightsCore,
	name string,
	opts *Options,
) DB

TracedNativeDBWrapperWithOptions returns a DB interface for the given driver and DSN WARNING: It will panic if the driver is not supported

type Hook added in v0.5.4

type Hook interface {
	AfterQuery(
		context context.Context,
		sid string,
		method string,
		query string,
		args []interface{},
		start_time time.Time,
		end_time time.Time,
		err error,
	)
	AfterBegin(
		context context.Context,
		sid string,
		start_time,
		end_time time.Time,
		err error,
	)
	AfterCommit(
		context context.Context,
		sid string,
		start_time,
		end_time time.Time,
		err error,
	)
	AfterRollback(
		context context.Context,
		start_time, end_time time.Time,
		err error,
	)
}

type Options added in v0.4.1

type Options struct {
	MaxIdleConns   int
	MaxOpenConns   int
	PanicablePings bool
	Name           string
	Hook           Hook
}

type Trx added in v0.4.5

type Trx interface {
	TraceDependency(
		ctx context.Context,
		spanId string,
		dependencyType string,
		serviceName string,
		commandName string,
		success bool,
		startTimestamp time.Time,
		eventTimestamp time.Time,
		fields map[string]string,
	)
	TraceException(
		ctx context.Context,
		err interface{},
		skip int,
		fields map[string]string,
	)
}

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (t *Tx) Commit() error

Commit commits the transaction.

func (*Tx) ExecContext

func (t *Tx) ExecContext(
	ctx context.Context,
	query string,
	args ...interface{},
) (sql.Result, error)

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. params:

  • query: query to execute
  • args: arguments to pass to query

returns:

  • sql.Result: result of query
  • error: error if any

func (*Tx) QueryContext

func (t *Tx) QueryContext(
	ctx context.Context,
	query string,
	args ...interface{},
) (*sql.Rows, error)

QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. params:

  • ctx: context
  • query: query to execute
  • args: arguments to pass to query

returns:

  • *sql.Rows: rows returned by query
  • error: error if any

func (*Tx) QueryRowContext

func (t *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. params:

  • query: query to execute
  • args: arguments to pass to query

returns:

  • *sql.Row: row returned by query

func (*Tx) Rollback

func (t *Tx) Rollback() error

Rollback aborts the transaction.

Jump to

Keyboard shortcuts

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