Documentation ¶
Index ¶
- Variables
- func Migrate(source string, db *sql.DB) error
- func NewMysqlConfig() *mysql.Config
- func NewMysqlStorage(config *mysql.Config) (*mysqlStorage, error)
- func NewTestDatabase(ctx context.Context, t *testing.T) (*mysqlStorage, string)
- type Account
- type Querier
- type Storage
- type Transaction
- type WaiterFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var TimeoutPingWaiter func(context.Context, time.Duration) WaiterFunc = func(parentCtx context.Context, timeout time.Duration) WaiterFunc { var err error ctx, cancel := context.WithTimeout(parentCtx, timeout) return func(db *sql.DB) (bool, error) { for { select { case <-ctx.Done(): cancel() if err != nil { err = errors.New(ctx.Err().Error() + ": " + err.Error()) } return false, err case <-time.After(1 * time.Second): if err = db.PingContext(ctx); err == nil { cancel() return false, nil } return true, err } } } }
TimeoutPingWaiter waits until the DB is available or fails on timeout
Functions ¶
func NewMysqlConfig ¶
NewMysqlConfig initializes new MySQL connection configuration with sane defaults
func NewMysqlStorage ¶
NewMysqlStorage creates and initializes new MySQL storage instance
Types ¶
type Storage ¶
type Storage interface { // WithTransaction wraps functions in transaction and rolls it back if function returns error WithTransaction(context.Context, func(context.Context, Querier) error) error WithTransactionStorage(context.Context, func(context.Context, Storage) error) error CreateAccount(ctx context.Context, name, iban, bic string, initialBalanceCents int64) (int64, error) FindAccount(ctx context.Context, id int64) (Account, error) UpdateAccountBalance(ctx context.Context, id, balance int64) error FindAccountByIBAN(ctx context.Context, iban string) (Account, error) FindAccountTransactions(ctx context.Context, id int64) ([]*Transaction, error) AppendAccountTransactions(ctx context.Context, transactions []*Transaction) error // Wait runs provided wait function until it returns true without error Wait(f WaiterFunc) error }
Storage defines interface to be satisfied by concrete storage implementation
type Transaction ¶
Click to show internal directories.
Click to hide internal directories.