db

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConnMaxIdleTime

func WithConnMaxIdleTime(d time.Duration) func(*DB) error

WithConnMaxIdleTime is a database option that sets the maximum idle time of a connection

func WithConnMaxLifetime

func WithConnMaxLifetime(d time.Duration) func(*DB) error

WithConnMaxLifetime is a database option that sets the maximum lifttime of a connection

func WithMaxIdelConns

func WithMaxIdelConns(conns int) func(*DB) error

WithMaxIdelConns is a database option that sets the maximum number of idle connections

func WithMaxOpenConns

func WithMaxOpenConns(conns int) func(*DB) error

WithMaxOpenConns is a database option that sets the maximum number of open connections

Types

type DB

type DB struct {
	DB        *sql.DB
	Connector driver.Connector

	// MaxOpenConns is the maximum number of open connections to the database.
	MaxOpenConns int
	// MaxIdelConns is the maximum number of connections in the idle connection pool.
	MaxIdelConns int
	// ConnMaxLifetime is the maximum lifetime of a connection.
	ConnMaxLifetime time.Duration
	// ConnMaxIdelTime is the maximum lifetime of an idle connection.
	ConnMaxIdelTime time.Duration
}

DB is the management interface for the standard database handle

func New

func New(connector driver.Connector, options ...func(*DB) error) (*DB, error)

New creates a new database object

func (*DB) Close

func (db *DB) Close()

Close closes the database connection

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Exec executes a query within a transaction that doesn't return rows

func (*DB) Ping

func (db *DB) Ping() error

Ping checks if the database is reachable

func (*DB) Query

func (db *DB) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query executes a query that is expected to return rows.

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRow executes a query that is expected to return at most one row.

func (*DB) WithTransaction

func (db *DB) WithTransaction(ctx context.Context, fn func(context.Context) error) error

WithTransaction executes a function within a transaction

type Scanable

type Scanable interface {
	Scan(dest ...interface{}) error
}

Jump to

Keyboard shortcuts

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