Documentation
¶
Index ¶
- Constants
- func AcquireAdvisoryLock(ctx context.Context, dbConnectionPool ConnectionPool, lockKey int) (bool, error)
- func Migrate(ctx context.Context, databaseURL string, direction migrate.MigrationDirection, ...) (int, error)
- func ReleaseAdvisoryLock(ctx context.Context, dbConnectionPool ConnectionPool, lockKey int) error
- func RunInTransaction(ctx context.Context, dbConnectionPool ConnectionPool, opts *sql.TxOptions, ...) error
- func RunInTransactionWithResult[T any](ctx context.Context, dbConnectionPool ConnectionPool, opts *sql.TxOptions, ...) (result T, err error)
- type ConnectionPool
- type ConnectionPoolImplementation
- func (db *ConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (Transaction, error)
- func (db *ConnectionPoolImplementation) Ping(ctx context.Context) error
- func (db *ConnectionPoolImplementation) SqlDB(ctx context.Context) (*sql.DB, error)
- func (db *ConnectionPoolImplementation) SqlxDB(ctx context.Context) (*sqlx.DB, error)
- type SQLExecuter
- type Transaction
Constants ¶
View Source
const ( MaxDBConnIdleTime = 10 * time.Second MaxOpenDBConns = 30 )
Variables ¶
This section is empty.
Functions ¶
func AcquireAdvisoryLock ¶
func AcquireAdvisoryLock(ctx context.Context, dbConnectionPool ConnectionPool, lockKey int) (bool, error)
AcquireAdvisoryLock attempt to acquire an advisory lock on the provided lockKey, returns true if acquired, or false not.
func ReleaseAdvisoryLock ¶
func ReleaseAdvisoryLock(ctx context.Context, dbConnectionPool ConnectionPool, lockKey int) error
ReleaseAdvisoryLock releases an advisory lock on the provided lockKey.
func RunInTransaction ¶
func RunInTransaction(ctx context.Context, dbConnectionPool ConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx Transaction) error) error
RunInTransaction runs the given atomic function in an atomic database transaction and returns an error. Boilerplate code for database transactions.
func RunInTransactionWithResult ¶
func RunInTransactionWithResult[T any](ctx context.Context, dbConnectionPool ConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx Transaction) (T, error)) (result T, err error)
RunInTransactionWithResult runs the given atomic function in an atomic database transaction and returns a result and an error. Boilerplate code for database transactions.
Types ¶
type ConnectionPool ¶
type ConnectionPool interface {
SQLExecuter
BeginTxx(ctx context.Context, opts *sql.TxOptions) (Transaction, error)
Close() error
Ping(ctx context.Context) error
SqlDB(ctx context.Context) (*sql.DB, error)
SqlxDB(ctx context.Context) (*sqlx.DB, error)
}
func OpenDBConnectionPool ¶
func OpenDBConnectionPool(dataSourceName string) (ConnectionPool, error)
type ConnectionPoolImplementation ¶
func (*ConnectionPoolImplementation) BeginTxx ¶
func (db *ConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (Transaction, error)
func (*ConnectionPoolImplementation) Ping ¶
func (db *ConnectionPoolImplementation) Ping(ctx context.Context) error
type SQLExecuter ¶
type SQLExecuter interface {
DriverName() string
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
sqlx.PreparerContext
sqlx.QueryerContext
Rebind(query string) string
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}
SQLExecuter is an interface that wraps the *sqlx.DB and *sqlx.Tx structs methods.
type Transaction ¶
type Transaction interface {
SQLExecuter
Rollback() error
Commit() error
}
Transaction is an interface that wraps the sqlx.Tx structs methods.
Click to show internal directories.
Click to hide internal directories.