database

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Db

type Db interface {
	Ping(ctx context.Context) error
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	QueryInt(ctx context.Context, sql string, args ...interface{}) (int64, error)
	Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	Pool() *pgxpool.Pool
	Close()
}

func New

func New(ctx context.Context, host, port, user, password, dbName string, opts ...Option) Db

type Dummy

type Dummy struct {
	Responses     []*Resp
	QueryCalls    int
	QueryRowCalls int
	ExecCalls     int
}

func NewDummy

func NewDummy() *Dummy

func (*Dummy) BeginTx

func (d *Dummy) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

func (*Dummy) Close

func (d *Dummy) Close()

func (*Dummy) Exec

func (d *Dummy) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)

func (*Dummy) Ping

func (d *Dummy) Ping(ctx context.Context) error

func (*Dummy) Pool

func (d *Dummy) Pool() *pgxpool.Pool

func (*Dummy) Query

func (d *Dummy) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

func (*Dummy) QueryInt

func (d *Dummy) QueryInt(ctx context.Context, sql string, args ...interface{}) (int64, error)

func (*Dummy) QueryRow

func (d *Dummy) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

type Option

type Option func(db *Postgres)

func WithConnectionTimeout

func WithConnectionTimeout(timeout time.Duration) Option

func WithHealthCheckPeriod

func WithHealthCheckPeriod(period time.Duration) Option

func WithMaxConnections

func WithMaxConnections(maxConnections int32) Option

func WithTLSConfig

func WithTLSConfig(tlsConf *tls.Config) Option

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

func (*Postgres) BeginTx

func (d *Postgres) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

func (*Postgres) Close

func (d *Postgres) Close()

func (*Postgres) Exec

func (d *Postgres) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)

func (*Postgres) Ping

func (d *Postgres) Ping(ctx context.Context) error

func (*Postgres) Pool

func (d *Postgres) Pool() *pgxpool.Pool

func (*Postgres) Query

func (d *Postgres) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

func (*Postgres) QueryInt

func (d *Postgres) QueryInt(ctx context.Context, sql string, args ...interface{}) (int64, error)

func (*Postgres) QueryRow

func (d *Postgres) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

type Resp

type Resp struct {
	Data interface{}
	Err  error
}

Jump to

Keyboard shortcuts

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