database

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query added in v0.0.2

func Query[T any](db Db, ctx context.Context, sql string, f func(row pgx.Rows) (*T, error), args ...interface{}) ([]*T, error)

func QueryRow added in v0.0.5

func QueryRow[T any](db Db, ctx context.Context, sql string, f func(ctx context.Context, row pgx.Rows) (*T, error), args ...interface{}) (*T, error)

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
	Tx            *DummyTx
}

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 DummyTx added in v0.0.3

type DummyTx struct {
	CalledCommit     bool
	CalledRollback   bool
	ExecError        error
	QueryRowResponse pgx.Row
}

func (*DummyTx) Begin added in v0.0.3

func (td *DummyTx) Begin(ctx context.Context) (pgx.Tx, error)

func (*DummyTx) Commit added in v0.0.3

func (td *DummyTx) Commit(ctx context.Context) error

func (*DummyTx) Conn added in v0.0.3

func (td *DummyTx) Conn() *pgx.Conn

func (*DummyTx) CopyFrom added in v0.0.3

func (td *DummyTx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*DummyTx) Exec added in v0.0.3

func (td *DummyTx) Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)

func (*DummyTx) LargeObjects added in v0.0.3

func (td *DummyTx) LargeObjects() pgx.LargeObjects

func (*DummyTx) Prepare added in v0.0.3

func (td *DummyTx) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*DummyTx) Query added in v0.0.3

func (td *DummyTx) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*DummyTx) QueryRow added in v0.0.3

func (td *DummyTx) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*DummyTx) Rollback added in v0.0.3

func (td *DummyTx) Rollback(ctx context.Context) error

func (*DummyTx) SendBatch added in v0.0.3

func (td *DummyTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

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