Documentation ¶
Overview ¶
Package repository contains all the functionality for working with the DB.
Index ¶
- func MigrateUp(logger *zap.SugaredLogger, db *sqlx.DB, path string) error
- type Operation
- type Repo
- func (r *Repo) CreateWallet(walletName string) error
- func (r *Repo) GetOperations(filter dto.OperationsFilter) ([]dto.Operation, error)
- func (r *Repo) GetWallet(walletName string) (*dto.Wallet, error)
- func (r *Repo) GetWalletsForUpdateTx(tx *sqlx.Tx, walletNames []string) ([]dto.Wallet, error)
- func (r *Repo) IncreaseWalletBalance(walletName string, amount uint64) error
- func (r *Repo) RunWithTransaction(f func(tx *sqlx.Tx) error) error
- func (r *Repo) TransferTx(tx *sqlx.Tx, walletFrom, walletTo string, amount uint64) error
- type Wallet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo performs database operations.
func NewRepoWithDB ¶
NewRepoWithDB creates instance of repository using existing DB.
func (*Repo) CreateWallet ¶
CreateWallet creates new wallet with unique name, or do nothing if wallet already exists.
func (*Repo) GetOperations ¶
GetOperations selects operations for specified wallet using filter. Operations ordered by time.
func (*Repo) GetWalletsForUpdateTx ¶
GetWalletsForUpdateTx selects wallets and obtains a lock for them at the database level using transaction. It will wait if some of the required wallets already locked in another goroutine.
func (*Repo) IncreaseWalletBalance ¶
IncreaseWalletBalance runs two operations in transaction:
- increases wallet balance;
- add new operation with type deposit.
func (*Repo) RunWithTransaction ¶
RunWithTransaction runs the given function inside a transaction.
func (*Repo) TransferTx ¶
TransferTx runs four operations using transaction:
- decreases balance of wallet_from if there is enough money;
- add new operation with type withdrawal for wallet_from;
- increases balance of wallet_to;
- add new operation with type deposit for wallet_to.