Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}
Executor is a type that implements the Exec, Query and QueryRow of pgx, it can be used to hide the types pgxpool.Pool, pgx.Conn,...
type Hooks ¶ added in v0.0.2
type Hooks struct {
BeforeStartTransaction func(*TxHelper, *pgxpool.Pool, context.Context) error
AfterStartTransaction func(*TxHelper, *pgxpool.Pool, pgx.Tx, context.Context) error
BeforeCommit func(*TxHelper, *pgxpool.Pool, pgx.Tx, context.Context) error
AfterCommit func(*TxHelper, *pgxpool.Pool, pgx.Tx, context.Context) error
BeforeRollback func(*TxHelper, *pgxpool.Pool, pgx.Tx, context.Context) error
AfterRollback func(*TxHelper, *pgxpool.Pool, pgx.Tx, context.Context) error
}
Hooks can be used to perform custom logic before or after certain events.
type Operation ¶
type Operation int
Operation defines the operation that will be performed on the database.
const ( // ReadOperation should be used for read only activities, such as selecting data. ReadOperation Operation = 1 << iota // InsertOperation should be used for the INSERT operation. InsertOperation // UpdateOperation should be used for the UPDATE operation. UpdateOperation // DeleteOperation should be used for the DELETE operation. DeleteOperation )
type TxHelper ¶
type TxHelper struct {
// contains filtered or unexported fields
}
TxHelper is a helper that can be used inside mappers. Its purpose is to assist the mappers with transaction handling.
func New ¶
New creates a new TxHelper that can be used inside mappers. Its purpose is to assist the mappers with transaction handling.
func (*TxHelper) GetExecutor ¶
GetExecutor gets the executor for the specified operation. The executor can be used to query the database. GetExecutor will start and return a transaction if there is no existing transaction AND if the operation is either a InsertOperation, UpdateOperation or DeleteOperation. In case of a non existing transaction and a ReadOperation GetExecutor will NOT start a transaction.