database

package
v0.0.0-...-b306714 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockPgxCollectableRowMethods

func MockPgxCollectableRowMethods(m *MockPgxCollectableRow, values []any, t *testing.T)

MockPgxCollectableRowMethods mocks all the methods of a MockPgxCollectableRow

func MockScan

func MockScan(mockPgxRow *MockPgxRow, values []any, t *testing.T)

MockScan mocks the "Scan" func

Types

type CollectRows

type CollectRows[T any] func(rows pgx.Rows) ([]T, error)

CollectRows is a wrapper created to be able to mock pgx.CollectRows function

func MakeCollectRows

func MakeCollectRows[T any](fn pgx.RowToFunc[T]) CollectRows[T]

MakeCollectRows creates a new CollectRows

func MockCollectRows

func MockCollectRows[T any](slice []T, err error) CollectRows[T]

MockCollectRows mocks CollectRows function

type Connection

type Connection interface {
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Begin(ctx context.Context) (pgx.Tx, error)
}

Connection is an interface created as an abstraction of pgxpool.Pool to be able to mock it

type MockPgxCollectableRow

type MockPgxCollectableRow struct {
	mock.Mock
}

MockPgxCollectableRow mock implementation of pgx.CollectableRow

func (*MockPgxCollectableRow) FieldDescriptions

func (m *MockPgxCollectableRow) FieldDescriptions() []pgconn.FieldDescription

func (*MockPgxCollectableRow) RawValues

func (m *MockPgxCollectableRow) RawValues() [][]byte

func (*MockPgxCollectableRow) Scan

func (m *MockPgxCollectableRow) Scan(dest ...any) error

func (*MockPgxCollectableRow) Values

func (m *MockPgxCollectableRow) Values() ([]any, error)

type MockPgxRow

type MockPgxRow struct {
	mock.Mock
}

MockPgxRow mock implementation of pgx.Row

func (*MockPgxRow) Scan

func (m *MockPgxRow) Scan(dest ...any) error

type MockPgxRows

type MockPgxRows struct {
	mock.Mock
}

MockPgxRows mock implementation of pgx.Rows

func (*MockPgxRows) Close

func (m *MockPgxRows) Close()

func (*MockPgxRows) CommandTag

func (m *MockPgxRows) CommandTag() pgconn.CommandTag

func (*MockPgxRows) Conn

func (m *MockPgxRows) Conn() *pgx.Conn

func (*MockPgxRows) Err

func (m *MockPgxRows) Err() error

func (*MockPgxRows) FieldDescriptions

func (m *MockPgxRows) FieldDescriptions() []pgconn.FieldDescription

func (*MockPgxRows) Next

func (m *MockPgxRows) Next() bool

func (*MockPgxRows) RawValues

func (m *MockPgxRows) RawValues() [][]byte

func (*MockPgxRows) Scan

func (m *MockPgxRows) Scan(dest ...any) error

func (*MockPgxRows) Values

func (m *MockPgxRows) Values() ([]any, error)

type MockPgxTx

type MockPgxTx struct {
	mock.Mock
}

MockPgxTx mock implementation of pgx.Tx

func (*MockPgxTx) Begin

func (t *MockPgxTx) Begin(ctx context.Context) (pgx.Tx, error)

func (*MockPgxTx) Commit

func (t *MockPgxTx) Commit(ctx context.Context) error

func (*MockPgxTx) Conn

func (t *MockPgxTx) Conn() *pgx.Conn

func (*MockPgxTx) CopyFrom

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

func (*MockPgxTx) Exec

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

func (*MockPgxTx) LargeObjects

func (t *MockPgxTx) LargeObjects() pgx.LargeObjects

func (*MockPgxTx) Prepare

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

func (*MockPgxTx) Query

func (t *MockPgxTx) Query(ctx context.Context, sql string, arguments ...any) (pgx.Rows, error)

func (*MockPgxTx) QueryRow

func (t *MockPgxTx) QueryRow(ctx context.Context, sql string, arguments ...any) pgx.Row

func (*MockPgxTx) Rollback

func (t *MockPgxTx) Rollback(ctx context.Context) error

func (*MockPgxTx) SendBatch

func (t *MockPgxTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

type MockPostgresConnection

type MockPostgresConnection struct {
	mock.Mock
}

MockPostgresConnection mock implementation of the postgres db

func (*MockPostgresConnection) Begin

func (m *MockPostgresConnection) Begin(ctx context.Context) (pgx.Tx, error)

func (*MockPostgresConnection) Exec

func (m *MockPostgresConnection) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)

func (*MockPostgresConnection) Query

func (m *MockPostgresConnection) Query(ctx context.Context, sql string, arguments ...any) (pgx.Rows, error)

func (*MockPostgresConnection) QueryRow

func (m *MockPostgresConnection) QueryRow(ctx context.Context, sql string, arguments ...any) pgx.Row

type Postgres

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

Postgres is the representation of a postgres database connection

func InitPostgres

func InitPostgres() (*Postgres, error)

InitPostgres creates a new postgres instance

func (*Postgres) Close

func (pg *Postgres) Close()

Close closes the database connection

func (*Postgres) Database

func (pg *Postgres) Database() *pgxpool.Pool

Database returns the Postgres connection pool

Jump to

Keyboard shortcuts

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