Documentation ¶
Index ¶
- Variables
- func GetStruct[T any](ctx context.Context, p Querier, query string, args ...any) (T, error)
- func IsUniqueError(err error, opts ...Option) bool
- func NewConnection(config Config) (*pgxpool.Pool, error)
- func NewQueryBuilder() goqu.DialectWrapper
- func SelectStruct[T any](ctx context.Context, p Querier, query string, args ...any) ([]T, error)
- type Acquirer
- type Config
- type Connector
- type Database
- type Executor
- type Listener
- type Logger
- type MockQuerier
- type MockQuerier_Expecter
- type MockQuerier_Query_Call
- func (_c *MockQuerier_Query_Call) Return(_a0 pgx.Rows, _a1 error) *MockQuerier_Query_Call
- func (_c *MockQuerier_Query_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *MockQuerier_Query_Call
- func (_c *MockQuerier_Query_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgx.Rows, error)) *MockQuerier_Query_Call
- type MockRows
- func (_m *MockRows) Close()
- func (_m *MockRows) CommandTag() pgconn.CommandTag
- func (_m *MockRows) Conn() *pgx.Conn
- func (_m *MockRows) EXPECT() *MockRows_Expecter
- func (_m *MockRows) Err() error
- func (_m *MockRows) FieldDescriptions() []pgconn.FieldDescription
- func (_m *MockRows) Next() bool
- func (_m *MockRows) RawValues() [][]byte
- func (_m *MockRows) Scan(dest ...interface{}) error
- func (_m *MockRows) Values() ([]interface{}, error)
- type MockRows_Close_Call
- type MockRows_CommandTag_Call
- type MockRows_Conn_Call
- type MockRows_Err_Call
- type MockRows_Expecter
- func (_e *MockRows_Expecter) Close() *MockRows_Close_Call
- func (_e *MockRows_Expecter) CommandTag() *MockRows_CommandTag_Call
- func (_e *MockRows_Expecter) Conn() *MockRows_Conn_Call
- func (_e *MockRows_Expecter) Err() *MockRows_Err_Call
- func (_e *MockRows_Expecter) FieldDescriptions() *MockRows_FieldDescriptions_Call
- func (_e *MockRows_Expecter) Next() *MockRows_Next_Call
- func (_e *MockRows_Expecter) RawValues() *MockRows_RawValues_Call
- func (_e *MockRows_Expecter) Scan(dest ...interface{}) *MockRows_Scan_Call
- func (_e *MockRows_Expecter) Values() *MockRows_Values_Call
- type MockRows_FieldDescriptions_Call
- func (_c *MockRows_FieldDescriptions_Call) Return(_a0 []pgconn.FieldDescription) *MockRows_FieldDescriptions_Call
- func (_c *MockRows_FieldDescriptions_Call) Run(run func()) *MockRows_FieldDescriptions_Call
- func (_c *MockRows_FieldDescriptions_Call) RunAndReturn(run func() []pgconn.FieldDescription) *MockRows_FieldDescriptions_Call
- type MockRows_Next_Call
- type MockRows_RawValues_Call
- type MockRows_Scan_Call
- type MockRows_Values_Call
- type Option
- type PgxListener
- type PgxPool
- func (p *PgxPool) Begin(ctx context.Context) (*PgxTx, error)
- func (p *PgxPool) BeginFunc(ctx context.Context, f func(conn Tx) error) error
- func (p *PgxPool) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (*PgxTx, error)
- func (p *PgxPool) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, f func(conn Tx) error) error
- func (p *PgxPool) Get(ctx context.Context, dst any, query string, args ...any) error
- func (p *PgxPool) Select(ctx context.Context, dest any, query string, args ...any) error
- type PgxTx
- func (p *PgxTx) Begin(ctx context.Context) (*PgxTx, error)
- func (p *PgxTx) BeginFunc(ctx context.Context, f func(conn Tx) error) error
- func (p *PgxTx) Get(ctx context.Context, dst any, query string, args ...any) error
- func (p *PgxTx) Select(ctx context.Context, dest any, query string, args ...any) error
- type Pinger
- type Querier
- type Result
- type Transactor
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ErrTxClosed = pgx.ErrTxClosed
Functions ¶
func IsUniqueError ¶
func NewConnection ¶
NewConnection creates a new connection pool with the given configurationand returns a pointer to the pool.
func NewQueryBuilder ¶
func NewQueryBuilder() goqu.DialectWrapper
Types ¶
type Config ¶
type Config struct { DataSourceName string // PostgreSQL connection string MaxIdleConns int // Maximum number of idle connections in the pool MaxOpenConns int // Maximum number of open connections in the pool ConnMaxLifetime time.Duration // Maximum amount of time a connection can be reused ConnMaxIdleTime time.Duration // Maximum amount of time a connection can be idle BeforeConnect func(context.Context, *pgx.ConnConfig) error AfterConnect func(context.Context, *pgx.Conn) error Logger *slog.Logger OmitArgs bool }
Config represents the configuration for establishing a connection pool.
type Executor ¶
type Executor interface { Begin(ctx context.Context) (*PgxTx, error) BeginFunc(ctx context.Context, f func(conn Tx) error) error Exec(ctx context.Context, query string, arguments ...any) (pgconn.CommandTag, error) Get(ctx context.Context, dst any, query string, args ...any) error Select(ctx context.Context, dest any, query string, args ...any) error }
type Listener ¶
type Listener interface { WaitForNotification(ctx context.Context) (*pgconn.Notification, error) Release() }
type MockQuerier ¶
MockQuerier is an autogenerated mock type for the Querier type
func NewMockQuerier ¶
func NewMockQuerier(t interface { mock.TestingT Cleanup(func()) }) *MockQuerier
NewMockQuerier creates a new instance of MockQuerier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockQuerier) EXPECT ¶
func (_m *MockQuerier) EXPECT() *MockQuerier_Expecter
type MockQuerier_Expecter ¶
type MockQuerier_Expecter struct {
// contains filtered or unexported fields
}
func (*MockQuerier_Expecter) Query ¶
func (_e *MockQuerier_Expecter) Query(ctx interface{}, query interface{}, args ...interface{}) *MockQuerier_Query_Call
Query is a helper method to define mock.On call
- ctx context.Context
- query string
- args ...interface{}
type MockQuerier_Query_Call ¶
MockQuerier_Query_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Query'
func (*MockQuerier_Query_Call) Return ¶
func (_c *MockQuerier_Query_Call) Return(_a0 pgx.Rows, _a1 error) *MockQuerier_Query_Call
func (*MockQuerier_Query_Call) Run ¶
func (_c *MockQuerier_Query_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *MockQuerier_Query_Call
func (*MockQuerier_Query_Call) RunAndReturn ¶
func (_c *MockQuerier_Query_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgx.Rows, error)) *MockQuerier_Query_Call
type MockRows ¶
MockRows is an autogenerated mock type for the Rows type
func NewMockRows ¶
NewMockRows creates a new instance of MockRows. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockRows) Close ¶
func (_m *MockRows) Close()
Close provides a mock function with given fields:
func (*MockRows) CommandTag ¶
func (_m *MockRows) CommandTag() pgconn.CommandTag
CommandTag provides a mock function with given fields:
func (*MockRows) EXPECT ¶
func (_m *MockRows) EXPECT() *MockRows_Expecter
func (*MockRows) FieldDescriptions ¶
func (_m *MockRows) FieldDescriptions() []pgconn.FieldDescription
FieldDescriptions provides a mock function with given fields:
type MockRows_Close_Call ¶
MockRows_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'
func (*MockRows_Close_Call) Return ¶
func (_c *MockRows_Close_Call) Return() *MockRows_Close_Call
func (*MockRows_Close_Call) Run ¶
func (_c *MockRows_Close_Call) Run(run func()) *MockRows_Close_Call
func (*MockRows_Close_Call) RunAndReturn ¶
func (_c *MockRows_Close_Call) RunAndReturn(run func()) *MockRows_Close_Call
type MockRows_CommandTag_Call ¶
MockRows_CommandTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CommandTag'
func (*MockRows_CommandTag_Call) Return ¶
func (_c *MockRows_CommandTag_Call) Return(_a0 pgconn.CommandTag) *MockRows_CommandTag_Call
func (*MockRows_CommandTag_Call) Run ¶
func (_c *MockRows_CommandTag_Call) Run(run func()) *MockRows_CommandTag_Call
func (*MockRows_CommandTag_Call) RunAndReturn ¶
func (_c *MockRows_CommandTag_Call) RunAndReturn(run func() pgconn.CommandTag) *MockRows_CommandTag_Call
type MockRows_Conn_Call ¶
MockRows_Conn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Conn'
func (*MockRows_Conn_Call) Return ¶
func (_c *MockRows_Conn_Call) Return(_a0 *pgx.Conn) *MockRows_Conn_Call
func (*MockRows_Conn_Call) Run ¶
func (_c *MockRows_Conn_Call) Run(run func()) *MockRows_Conn_Call
func (*MockRows_Conn_Call) RunAndReturn ¶
func (_c *MockRows_Conn_Call) RunAndReturn(run func() *pgx.Conn) *MockRows_Conn_Call
type MockRows_Err_Call ¶
MockRows_Err_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Err'
func (*MockRows_Err_Call) Return ¶
func (_c *MockRows_Err_Call) Return(_a0 error) *MockRows_Err_Call
func (*MockRows_Err_Call) Run ¶
func (_c *MockRows_Err_Call) Run(run func()) *MockRows_Err_Call
func (*MockRows_Err_Call) RunAndReturn ¶
func (_c *MockRows_Err_Call) RunAndReturn(run func() error) *MockRows_Err_Call
type MockRows_Expecter ¶
type MockRows_Expecter struct {
// contains filtered or unexported fields
}
func (*MockRows_Expecter) Close ¶
func (_e *MockRows_Expecter) Close() *MockRows_Close_Call
Close is a helper method to define mock.On call
func (*MockRows_Expecter) CommandTag ¶
func (_e *MockRows_Expecter) CommandTag() *MockRows_CommandTag_Call
CommandTag is a helper method to define mock.On call
func (*MockRows_Expecter) Conn ¶
func (_e *MockRows_Expecter) Conn() *MockRows_Conn_Call
Conn is a helper method to define mock.On call
func (*MockRows_Expecter) Err ¶
func (_e *MockRows_Expecter) Err() *MockRows_Err_Call
Err is a helper method to define mock.On call
func (*MockRows_Expecter) FieldDescriptions ¶
func (_e *MockRows_Expecter) FieldDescriptions() *MockRows_FieldDescriptions_Call
FieldDescriptions is a helper method to define mock.On call
func (*MockRows_Expecter) Next ¶
func (_e *MockRows_Expecter) Next() *MockRows_Next_Call
Next is a helper method to define mock.On call
func (*MockRows_Expecter) RawValues ¶
func (_e *MockRows_Expecter) RawValues() *MockRows_RawValues_Call
RawValues is a helper method to define mock.On call
func (*MockRows_Expecter) Scan ¶
func (_e *MockRows_Expecter) Scan(dest ...interface{}) *MockRows_Scan_Call
Scan is a helper method to define mock.On call
- dest ...interface{}
func (*MockRows_Expecter) Values ¶
func (_e *MockRows_Expecter) Values() *MockRows_Values_Call
Values is a helper method to define mock.On call
type MockRows_FieldDescriptions_Call ¶
MockRows_FieldDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FieldDescriptions'
func (*MockRows_FieldDescriptions_Call) Return ¶
func (_c *MockRows_FieldDescriptions_Call) Return(_a0 []pgconn.FieldDescription) *MockRows_FieldDescriptions_Call
func (*MockRows_FieldDescriptions_Call) Run ¶
func (_c *MockRows_FieldDescriptions_Call) Run(run func()) *MockRows_FieldDescriptions_Call
func (*MockRows_FieldDescriptions_Call) RunAndReturn ¶
func (_c *MockRows_FieldDescriptions_Call) RunAndReturn(run func() []pgconn.FieldDescription) *MockRows_FieldDescriptions_Call
type MockRows_Next_Call ¶
MockRows_Next_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Next'
func (*MockRows_Next_Call) Return ¶
func (_c *MockRows_Next_Call) Return(_a0 bool) *MockRows_Next_Call
func (*MockRows_Next_Call) Run ¶
func (_c *MockRows_Next_Call) Run(run func()) *MockRows_Next_Call
func (*MockRows_Next_Call) RunAndReturn ¶
func (_c *MockRows_Next_Call) RunAndReturn(run func() bool) *MockRows_Next_Call
type MockRows_RawValues_Call ¶
MockRows_RawValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RawValues'
func (*MockRows_RawValues_Call) Return ¶
func (_c *MockRows_RawValues_Call) Return(_a0 [][]byte) *MockRows_RawValues_Call
func (*MockRows_RawValues_Call) Run ¶
func (_c *MockRows_RawValues_Call) Run(run func()) *MockRows_RawValues_Call
func (*MockRows_RawValues_Call) RunAndReturn ¶
func (_c *MockRows_RawValues_Call) RunAndReturn(run func() [][]byte) *MockRows_RawValues_Call
type MockRows_Scan_Call ¶
MockRows_Scan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Scan'
func (*MockRows_Scan_Call) Return ¶
func (_c *MockRows_Scan_Call) Return(_a0 error) *MockRows_Scan_Call
func (*MockRows_Scan_Call) Run ¶
func (_c *MockRows_Scan_Call) Run(run func(dest ...interface{})) *MockRows_Scan_Call
func (*MockRows_Scan_Call) RunAndReturn ¶
func (_c *MockRows_Scan_Call) RunAndReturn(run func(...interface{}) error) *MockRows_Scan_Call
type MockRows_Values_Call ¶
MockRows_Values_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Values'
func (*MockRows_Values_Call) Return ¶
func (_c *MockRows_Values_Call) Return(_a0 []interface{}, _a1 error) *MockRows_Values_Call
func (*MockRows_Values_Call) Run ¶
func (_c *MockRows_Values_Call) Run(run func()) *MockRows_Values_Call
func (*MockRows_Values_Call) RunAndReturn ¶
func (_c *MockRows_Values_Call) RunAndReturn(run func() ([]interface{}, error)) *MockRows_Values_Call
type Option ¶
func WithConstraintName ¶
type PgxListener ¶
type PgxListener struct {
// contains filtered or unexported fields
}
func NewListener ¶
func (*PgxListener) Release ¶
func (l *PgxListener) Release()
func (*PgxListener) WaitForNotification ¶
func (l *PgxListener) WaitForNotification(ctx context.Context) (*pgconn.Notification, error)
type PgxPool ¶
PgxPool is a PostgreSQL wrapper that implements the Executor interface.
func NewPgxPool ¶
func (*PgxPool) BeginFunc ¶
BeginFunc starts a transaction and executes the given function within that transaction.
func (*PgxPool) BeginTxFunc ¶
func (p *PgxPool) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, f func(conn Tx) error) error
BeginTxFunc starts a transaction and executes the given function within that transaction.
type PgxTx ¶
type PgxTx struct {
pgx.Tx
}
PgxTx is a PostgreSQL transaction wrapper that implements the Executor interface.
func (*PgxTx) BeginFunc ¶
BeginFunc starts a nested transaction and executes the given function within that transaction.
type Transactor ¶
type Tx ¶
type Tx interface { Executor Transactor }