db

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextAfterTransaction

func ContextAfterTransaction(ctx context.Context) context.Context

ContextAfterTransaction preserves request values for compensation while removing cancellation and the completed transaction handle.

func CtxWithTransaction

func CtxWithTransaction(ctx context.Context, tx *gorm.DB) context.Context

func Migrate

func Migrate(g2 *gorm.DB)

func OnPostCommit

func OnPostCommit(ctx context.Context, fn func())

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

func OnRollback(ctx context.Context, fn func(context.Context) error) error

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.

func TxFromContext

func TxFromContext(ctx context.Context) *gorm.DB

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 (f *Session) CheckConnection() error

func (*Session) Close

func (f *Session) Close() error

func (*Session) DirectDB

func (f *Session) DirectDB() *sql.DB

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.

func (*Session) New

func (f *Session) New(ctx context.Context) *gorm.DB

type SessionFactory

type SessionFactory interface {
	Init(*config.DatabaseConfig)
	DirectDB() *sql.DB
	New(ctx context.Context) *gorm.DB
	CheckConnection() error
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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