Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddUserParams ¶
type AddUserParams struct {
db.CreateUserParams
AfterCreate func(user db.User) error
}
type AddUserResult ¶
type Bank ¶
type Bank interface {
db.Querier
Transfer(ctx context.Context, arg TransferParams) (TransferResult, error)
AddUser(ctx context.Context, arg AddUserParams) (AddUserResult, error)
}
Bank defines all functions to execute db queries and transactions
type SQLBank ¶
SQLBank a composition that provides transactions over multiple database queries. Composition allows you to build complex types by combining simpler types, promoting code modularity and flexibility.
func (*SQLBank) AddUser ¶
func (store *SQLBank) AddUser(ctx context.Context, arg AddUserParams) (AddUserResult, error)
func (*SQLBank) Transfer ¶
func (bank *SQLBank) Transfer(ctx context.Context, transfer TransferParams) (TransferResult, error)
Transfer performs a money transfer from one account to the other. It creates the transfer, add account entries, and update accounts' balance within a database transaction.
type TransferParams ¶
type TransferParams struct {
FromAccountID int64 `json:"from_account_id"`
ToAccountID int64 `json:"to_account_id"`
Amount int64 `json:"amount"`
}
TransferParams contains the input parameters of the transfer transaction
type TransferResult ¶
type TransferResult struct {
// Created transfer record
Transfer db.Transfer `json:"transfer"`
// From account after its balance is updated
FromAccount db.Account `json:"from_account"`
// To account after its balance is updated
ToAccount db.Account `json:"to_account"`
// From entry records that money is moving out
FromEntry db.Entry `json:"from_entry"`
// To entry records that money is moving in
ToEntry db.Entry `json:"to_entry"`
}
TransferResult is the result of the transfer transaction
Click to show internal directories.
Click to hide internal directories.