sqldb

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 8 Imported by: 4

Documentation

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
	WithLogger(l *zap.Logger) DB
}

func DBProvider

func DBProvider(Driver string, DSN string) DB

DBProvider 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 *tracer.AppInsightsCore,
	name string,
) DB

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

type Tx

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

func (*Tx) Commit

func (t *Tx) Commit() error

Commit commits the transaction. params:

  • none

returns:

  • error: error if any

func (*Tx) Exec

func (t *Tx) Exec(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) 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) Query

func (t *Tx) Query(query string, args ...interface{}) (*sql.Rows, 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) QueryRow

func (t *Tx) QueryRow(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) 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. params:

  • none

returns:

  • error: error if any

Jump to

Keyboard shortcuts

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