Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultOptions() pogreb.Options
- type Account
- type DBService
- func (s *DBService) Backup(user *User) (string, error)
- func (service *DBService) Close()
- func (s *DBService) CountTransactions(user *User, options TransactionFilterOptions) (uint64, error)
- func (s *DBService) CreateAccount(user *User, account *Account) error
- func (s *DBService) CreateTransaction(user *User, transaction *Transaction) error
- func (s *DBService) DeleteAccount(user *User, accountUUID string) error
- func (s *DBService) DeleteTransaction(user *User, transactionUUID string) error
- func (service *DBService) GC()
- func (s *DBService) GetAccount(user *User, accountUUID string) (*Account, error)
- func (s *DBService) GetAccounts(user *User) ([]*Account, error)
- func (s *DBService) GetOrCreateConfigVariable(varName string, generator func() (string, error)) (string, error)
- func (s *DBService) GetTags(user *User) ([]string, error)
- func (s *DBService) GetTransaction(user *User, transactionUUID string) (*Transaction, error)
- func (s *DBService) GetTransactions(user *User, options GetTransactionOptions) ([]*Transaction, error)
- func (s *DBService) GetUser(username string) (*User, error)
- func (s *DBService) Restore(user *User, value string) error
- func (s *DBService) SaveUser(user *User) error
- func (s *DBService) SetConfigVariable(varName, varValue string) error
- func (s *DBService) UpdateAccount(user *User, account *Account) error
- func (s *DBService) UpdateTransaction(user *User, transaction *Transaction) error
- type GetTransactionOptions
- type Transaction
- type TransactionComponent
- type TransactionFilterOptions
- type User
Constants ¶
const ( // TransactionTypeExpenseIncome is an Expense/Income transaction (totals do not have to be equal). TransactionTypeExpenseIncome = iota // TransactionTypeTransfer is a Transfer transaction (totals for each currency should be zero). TransactionTypeTransfer )
Variables ¶
var ErrUserAlreadyExists = fmt.Errorf("uuid conflicts with existing user")
ErrUserAlreadyExists is an error when a user cannot be renamed because their username is already in use.
var GetAllTransactionsOptions = GetTransactionOptions{Offset: 0, Limit: ^uint64(0)}
GetAllTransactionsOptions is a GetTransactionOptions which returns all transactions in one page.
Functions ¶
func DefaultOptions ¶
DefaultOptions returns default options for the database, customized based on environment variables.
Types ¶
type Account ¶
type Account struct { UUID string Name string Balance int64 Currency string IncludeInTotal bool ShowInList bool }
Account keeps the balance and other details for an account.
type DBService ¶
type DBService struct {
// contains filtered or unexported fields
}
DBService provides services for reading and writing structs in the database.
func (*DBService) CountTransactions ¶
func (s *DBService) CountTransactions(user *User, options TransactionFilterOptions) (uint64, error)
CountTransactions returns the number of transactions matching the filter options.
func (*DBService) CreateAccount ¶
CreateAccount creates and saves the specified account. It generates sets the ID to the generated account ID.
func (*DBService) CreateTransaction ¶
func (s *DBService) CreateTransaction(user *User, transaction *Transaction) error
CreateTransaction saves a new Transaction into the database.
func (*DBService) DeleteAccount ¶
DeleteAccount deletes an account by its UUID. If the account doesn't exist, it returns an error.
func (*DBService) DeleteTransaction ¶
DeleteTransaction deletes a Transaction and its sort index key by its UUID. Deleting a transaction also updates the affected Account balance. If transaction doesn't exist, returns an error.
func (*DBService) GC ¶
func (service *DBService) GC()
GC deletes expired items and attempts to perform a database cleanup.
func (*DBService) GetAccount ¶
GetAccount returns an Account by its UUID. If the Account doesn't exist, it returns nil.
func (*DBService) GetAccounts ¶
GetAccounts returns all accounts for user.
func (*DBService) GetOrCreateConfigVariable ¶
func (s *DBService) GetOrCreateConfigVariable(varName string, generator func() (string, error)) (string, error)
GetOrCreateConfigVariable returns the value for the varName ServerConfig variable, or if there's no entry, uses generator to create and save a value.
func (*DBService) GetTransaction ¶
func (s *DBService) GetTransaction(user *User, transactionUUID string) (*Transaction, error)
GetTransaction returns a Transaction by its UUID. If the Transaction doesn't exist, it returns nil.
func (*DBService) GetTransactions ¶
func (s *DBService) GetTransactions(user *User, options GetTransactionOptions) ([]*Transaction, error)
GetTransactions returns transactions for user matching the filter and paging options. Returns an empty list if no transactions match the options.
func (*DBService) GetUser ¶
GetUser returns the User by username. If user doesn't exist, returns nil.
func (*DBService) SetConfigVariable ¶
SetConfigVariable returns the value for the varName ServerConfig variable, or nil if no value is saved.
func (*DBService) UpdateAccount ¶
UpdateAccount saves an already existing account. If the account doesn't exist, it returns an error.
func (*DBService) UpdateTransaction ¶
func (s *DBService) UpdateTransaction(user *User, transaction *Transaction) error
UpdateTransaction updates an existing Transaction in the database.
type GetTransactionOptions ¶
type GetTransactionOptions struct { Offset uint64 Limit uint64 TransactionFilterOptions }
GetTransactionOptions specifies paging and filtering options for retrieving transactions.
type Transaction ¶
type Transaction struct { UUID string Description string Type int Tags []string Date string Components []TransactionComponent }
Transaction saves details for one expense item.
type TransactionComponent ¶
TransactionComponent contains details for a part of a Transaction.
type TransactionFilterOptions ¶
type TransactionFilterOptions struct { FilterDescription string FilterFromDate string FilterToDate string FilterTags []string FilterAccounts []string ExcludeExpenseIncome bool ExcludeTransfer bool }
TransactionFilterOptions specifies filter parameters for Transactions.
func (*TransactionFilterOptions) IsEmpty ¶
func (options *TransactionFilterOptions) IsEmpty() bool
IsEmpty returns if options do not apply any filtering (all transactions match this filter).
func (*TransactionFilterOptions) Matches ¶
func (options *TransactionFilterOptions) Matches(transaction *Transaction) bool
Matches returns true if transaction is accepted by the filter.
type User ¶
User keeps configuration for a user and information used to link a user with their data.
func (*User) GetUsername ¶
GetUsername returns the user's current username.
func (*User) SetPassword ¶
SetPassword sets a new password for user. The password is hashed and salted with bcrypt.
func (*User) SetUsername ¶
SetUsername sets a new username for User which will be updated when SaveUser is called.
func (*User) ValidatePassword ¶
ValidatePassword checks if password matches the user's password.