Skip to content

Instantly share code, notes, and snippets.

@jfeng45
Last active July 23, 2019 12:27
Show Gist options
  • Save jfeng45/3326625cbc6a8a11e0bb78d489296e7e to your computer and use it in GitHub Desktop.
Save jfeng45/3326625cbc6a8a11e0bb78d489296e7e to your computer and use it in GitHub Desktop.
transaction interface for database handler
// Transactioner is the transaction interface for database handler
// It should only be applicable to SQL database
type Transactioner interface {
// Rollback a transaction
Rollback() error
// Commit a transaction
Commit() error
// TxEnd commits a transaction if no errors, otherwise rollback
// txFunc is the operations wrapped in a transaction
TxEnd(txFunc func() error) error
// TxBegin gets *sql.DB from receiver and return a SqlGdbc, which has a *sql.Tx
TxBegin() (SqlGdbc, error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment