Documentation
¶
Index ¶
- func ContextAfterTransaction(ctx context.Context) context.Context
- func CtxWithTransaction(ctx context.Context, tx *gorm.DB) context.Context
- func Migrate(g2 *gorm.DB)
- func OnPostCommit(ctx context.Context, fn func())
- func OnRollback(ctx context.Context, fn func(context.Context) error) error
- func TxFromContext(ctx context.Context) *gorm.DB
- type PostCommitHooks
- type Session
- type SessionFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextAfterTransaction ¶
ContextAfterTransaction preserves request values for compensation while removing cancellation and the completed transaction handle.
func OnPostCommit ¶
OnPostCommit registers fn to run after the outermost transaction commits. If called outside a transaction, fn runs immediately. Hooks are fire-and-forget: errors are logged by the caller inside fn, not propagated, because the transaction is already committed.
func OnRollback ¶
OnRollback registers a compensation owned by the outermost transaction. The callback receives a non-cancelled context without the completed transaction, so it can safely perform database or external cleanup after a rollback. Registering outside an atomic transaction is an error.
Types ¶
type PostCommitHooks ¶
type PostCommitHooks struct {
// contains filtered or unexported fields
}
func CtxWithPostCommitHooks ¶
func CtxWithPostCommitHooks(ctx context.Context) (context.Context, *PostCommitHooks)
func (*PostCommitHooks) Run ¶
func (h *PostCommitHooks) Run()
func (*PostCommitHooks) RunRollback ¶
func (h *PostCommitHooks) RunRollback(ctx context.Context) []error
RunRollback runs compensations in reverse registration order. Every hook is attempted; a hook error or panic is returned to the transaction owner for logging and never prevents the remaining compensations from running.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSessionFactory ¶
func NewSessionFactory(config *config.DatabaseConfig) *Session
func (*Session) CheckConnection ¶
func (*Session) Init ¶
func (f *Session) Init(config *config.DatabaseConfig)
Init will initialize a singleton connection as needed and return the same instance. Go includes database connection pooling in the platform. Gorm uses the same and provides a method to clone a connection via New(), which is safe for use by concurrent Goroutines.