Documentation ¶
Overview ¶
Package database has a database client to access the transactions and account database together with helpers to interact with those tables
Index ¶
- Variables
- type Account
- type AccountBalance
- type AccountType
- type BaseModel
- type Client
- func (c *Client) CreateAccount(name string, accType AccountType) (a Account, err error)
- func (c *Client) CreateTransaction(tx Transaction) (ntx Transaction, err error)
- func (c *Client) DeleteTransaction(id uuid.UUID) (err error)
- func (c *Client) GetAccount(id uuid.UUID) (a Account, err error)
- func (c *Client) GetTransactionByID(id uuid.UUID) (tx Transaction, err error)
- func (c *Client) ListAccountBalances(showHidden bool) (a []AccountBalance, err error)
- func (c *Client) ListAccounts(showHidden bool) (a []Account, err error)
- func (c *Client) ListAccountsByType(at AccountType, showHidden bool) (a []Account, err error)
- func (c *Client) ListTransactions(since, until time.Time) (txs []Transaction, err error)
- func (c *Client) ListTransactionsByAccount(acc uuid.UUID, since, until time.Time) (txs []Transaction, err error)
- func (c *Client) MarkAccountReconciled(acc uuid.UUID) (err error)
- func (c *Client) TransferMoney(from, to uuid.UUID, amount float64, description string) (err error)
- func (c *Client) TransferMoneyWithCategory(from, to uuid.UUID, amount float64, description string, category uuid.UUID) (err error)
- func (c *Client) UpdateAccountHidden(id uuid.UUID, hidden bool) (err error)
- func (c *Client) UpdateAccountName(id uuid.UUID, name string) (err error)
- func (c *Client) UpdateTransaction(txID uuid.UUID, tx Transaction) (err error)
- func (c *Client) UpdateTransactionCategory(id uuid.UUID, cat uuid.UUID) (err error)
- func (c *Client) UpdateTransactionCleared(id uuid.UUID, cleared bool) (err error)
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( // UnallocatedMoney is a category UUID which is automatically created // during database migration phase and therefore always available UnallocatedMoney = makeConstAcctID(1) // StartingBalance is a category UUID which is automatically created // and hidden during database migration and used in frontend as constant StartingBalance = makeConstAcctID(2) //nolint:gomnd )
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { BaseModel Name string `json:"name"` Type AccountType `json:"type"` Hidden bool `json:"hidden"` }
Account represents a budget, tracking or category account - in general something holding money through the sum of transactions
type AccountBalance ¶
AccountBalance wraps an Account and adds the balance
type AccountType ¶
type AccountType string
AccountType represents the type of an account
const ( AccountTypeBudget AccountType = "budget" AccountTypeCategory AccountType = "category" AccountTypeTracking AccountType = "tracking" )
Known values of the AccountType enum
func (AccountType) IsValid ¶
func (a AccountType) IsValid() bool
IsValid checks whether the given AccountType belongs to the known types
type BaseModel ¶
type BaseModel struct { ID uuid.UUID `gorm:"type:uuid" json:"id"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` }
BaseModel is used internally in all other models for common fields
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the database client
func (*Client) CreateAccount ¶
func (c *Client) CreateAccount(name string, accType AccountType) (a Account, err error)
CreateAccount creates and returns a new account of the given type
func (*Client) CreateTransaction ¶
func (c *Client) CreateTransaction(tx Transaction) (ntx Transaction, err error)
CreateTransaction takes a prepared transaction and stores it
func (*Client) DeleteTransaction ¶
DeleteTransaction deletes a transaction
func (*Client) GetAccount ¶
GetAccount retrieves an Account using its ID
func (*Client) GetTransactionByID ¶
func (c *Client) GetTransactionByID(id uuid.UUID) (tx Transaction, err error)
GetTransactionByID returns a single transaction by its ID
func (*Client) ListAccountBalances ¶
func (c *Client) ListAccountBalances(showHidden bool) (a []AccountBalance, err error)
ListAccountBalances returns a list of accounts with their corresponding balance
func (*Client) ListAccounts ¶
ListAccounts returns a list of all accounts
func (*Client) ListAccountsByType ¶
func (c *Client) ListAccountsByType(at AccountType, showHidden bool) (a []Account, err error)
ListAccountsByType returns a list of all accounts of the given type
func (*Client) ListTransactions ¶
func (c *Client) ListTransactions(since, until time.Time) (txs []Transaction, err error)
ListTransactions retrieves all transactions
func (*Client) ListTransactionsByAccount ¶
func (c *Client) ListTransactionsByAccount(acc uuid.UUID, since, until time.Time) (txs []Transaction, err error)
ListTransactionsByAccount retrieves all transactions for an account or category
func (*Client) MarkAccountReconciled ¶ added in v0.3.0
MarkAccountReconciled marks all cleared transactions as reconciled. The account balance is NOT checked in this method.
func (*Client) TransferMoney ¶
TransferMoney creates new Transactions for the given account transfer. The account type of the from and to account must match for this to work.
func (*Client) TransferMoneyWithCategory ¶
func (c *Client) TransferMoneyWithCategory(from, to uuid.UUID, amount float64, description string, category uuid.UUID) (err error)
TransferMoneyWithCategory creates new Transactions for the given account transfer. This is not possible for category type accounts.
func (*Client) UpdateAccountHidden ¶
UpdateAccountHidden updates the hidden flag for the given Account
func (*Client) UpdateAccountName ¶
UpdateAccountName sets a new name for the given account ID
func (*Client) UpdateTransaction ¶
func (c *Client) UpdateTransaction(txID uuid.UUID, tx Transaction) (err error)
UpdateTransaction takes a transaction, fetches the stored transaction applies some sanity actions and stores it back to the database
func (*Client) UpdateTransactionCategory ¶
UpdateTransactionCategory modifies the category of the given transaction. (It is not possible to remove a category with this)
type Transaction ¶
type Transaction struct { BaseModel Time time.Time `json:"time"` Payee string `json:"payee"` Description string `json:"description"` Amount float64 `json:"amount"` Account uuid.NullUUID `gorm:"type:uuid" json:"account"` Category uuid.NullUUID `gorm:"type:uuid" json:"category"` Cleared bool `json:"cleared"` Reconciled bool `json:"reconciled"` PairKey uuid.NullUUID `gorm:"type:uuid" json:"-"` }
Transaction represents some money movement between, from or to accounts
func (Transaction) Validate ¶
func (t Transaction) Validate(c *Client) (err error)
Validate executes some basic checks on the transaction