{"modulePath":"github.com/Stackdome/stackdome","version":"v0.0.7-alpha","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package db\n\n## Functions\n\n```go\nfunc ContextAfterTransaction(ctx context.Context) context.Context\n```\nContextAfterTransaction preserves request values for compensation while removing cancellation and the completed transaction handle.\n\n```go\nfunc CtxWithTransaction(ctx context.Context, tx *gorm.DB) context.Context\n```\n\n```go\nfunc Migrate(g2 *gorm.DB)\n```\n\n```go\nfunc OnPostCommit(ctx context.Context, fn func())\n```\nOnPostCommit 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.\n\n```go\nfunc OnRollback(ctx context.Context, fn func(context.Context) error) error\n```\nOnRollback 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.\n\n```go\nfunc TxFromContext(ctx context.Context) *gorm.DB\n```\n\n## Types\n\n```go\ntype PostCommitHooks struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc CtxWithPostCommitHooks(ctx context.Context) (context.Context, *PostCommitHooks)\n```\n\n```go\nfunc (h *PostCommitHooks) Run()\n```\n\n```go\nfunc (h *PostCommitHooks) RunRollback(ctx context.Context) []error\n```\nRunRollback 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.\n\n```go\ntype Session struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewSessionFactory(config *config.DatabaseConfig) *Session\n```\n\n```go\nfunc (f *Session) CheckConnection() error\n```\n\n```go\nfunc (f *Session) Close() error\n```\n\n```go\nfunc (f *Session) DirectDB() *sql.DB\n```\n\n```go\nfunc (f *Session) Init(config *config.DatabaseConfig)\n```\nInit 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.\n\n```go\nfunc (f *Session) New(ctx context.Context) *gorm.DB\n```\n\n```go\ntype SessionFactory interface {\n\tInit(*config.DatabaseConfig)\n\tDirectDB() *sql.DB\n\tNew(ctx context.Context) *gorm.DB\n\tCheckConnection() error\n\tClose() error\n}\n```\n\n","path":"github.com/Stackdome/stackdome/pkg/db","name":"db","synopsis":"","isRedistributable":true}
