Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transaction ¶
func Transaction(ctx context.Context, conn *gorm.DB, handler TransactionHandler, afterCommitFns ...func()) (err error)
Transaction handles a task under transaction. It's NOT concurrency-safe.
Transaction creates a transaction automatically if there is no available transaction in the context, otherwise reuse the existing one. The existing transaction instance is passed to the context.
Example usage:
type Storage struct { conn *gorm.DB } func (s *Storage) CreateUser(ctx context.Context, user *User) error { return Transaction(ctx, s.conn, func(ctx context.Context, tx *gorm.DB) error { return tx.Create(user).Error }) }
Types ¶
type Config ¶
type Config struct { gorm.Config DSN string MaxIdleConns int // the maximum number of connections in the idle connection pool. MaxOpenConns int // the maximum number of open connections to the database. MaxLifetime time.Duration // the maximum amount of time a connection may be reused. MaxIdleTime time.Duration // the maximum amount of time a connection may be idle. }
Config connection config
Click to show internal directories.
Click to hide internal directories.