findb

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package findb contains the persistence layer for the fin package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ConcurrentUpdate = errors.New("findb: Concurrent update.")
	NoSuchId         = errors.New("findb: No Such Id.")
	WrongPassword    = errors.New("findb: Wrong password.")
	NoPermission     = errors.New("findb: Insufficient permission.")
)

Functions

func ApplyRecurringEntries

func ApplyRecurringEntries(
	t db.Transaction,
	store RecurringEntriesApplier,
	acctId int64,
	currentDate time.Time) (int, error)

ApplyRecurringEntries applies all outstanding recurring entries and returns how many new entries were added to the database as a result. If there are no outstanding recurring entries, this function does nothing and returns 0. Note that ApplyRecurringEntries is idempotent. t is the database transaction and must be non-nil. store is the database store. If acctId is non-zero, ApplyRecurringEntries applies only the outstanding recurring entries pertaining to that account. currentDate is the current date.

func ApplyRecurringEntriesDryRun

func ApplyRecurringEntriesDryRun(
	t db.Transaction,
	store RecurringEntriesRunner,
	acctId int64,
	currentDate time.Time) (int, error)

ApplyRecurringEntriesDryRun returns out how many new entries would be added to the database if ApplyRecurringEntries were run. t is the database transaction. store is the database store. If acctId is non-zero, ApplyRecurringEntriesDryRun considers only the outstanding recurring entries pertaining to that account. currentDate is the current date.

func ApplyRecurringEntry

func ApplyRecurringEntry(
	t db.Transaction,
	store RecurringEntryApplier,
	id int64) (bool, error)

ApplyRecurringEntry advances the recurring entry with given id creating one new entry for it. t is the database transaction and must be non-nil. Returns true if the entry was applied or false if the NumLeft field has already reached 0.

func LoginUser

func LoginUser(
	t db.Transaction,
	store UpdateUserByNameRunner,
	userName string,
	password string,
	currentTime time.Time,
	user *fin.User) error

LoginUser logs in a user. Caller responsible for setting any cookies resulting from login. On success, LoginUser sets logged in user at user. If userName is wrong, LoginUser returns NoSuchId. If password is wrong, LoginUser returns WrongPassword.

func SkipRecurringEntry

func SkipRecurringEntry(
	t db.Transaction,
	store RecurringEntrySkipper,
	id int64) (bool, error)

SkipRecurringEntry advances the recurring entry with given id without creating a new entry for it. t is the database transaction and must be non-nil. Returns true if the entry was skipped or false if the NumLeft field has already reached 0.

Types

type AccountByIdRunner

type AccountByIdRunner interface {
	// AccountById fetches an account by Id.
	AccountById(t db.Transaction, acctId int64, account *fin.Account) error
}

type AccountsRunner

type AccountsRunner interface {
	// Accounts fetches all accounts.
	Accounts(t db.Transaction, consumer goconsume.Consumer) error
}

type ActiveAccountsRunner

type ActiveAccountsRunner interface {
	// ActiveAccounts fetches all active accounts sorted by name.
	ActiveAccounts(t db.Transaction) (accounts []*fin.Account, err error)
}

type AddAccountRunner

type AddAccountRunner interface {
	// AddAccount adds a new account.
	AddAccount(t db.Transaction, Account *fin.Account) error
}

type AddRecurringEntryRunner

type AddRecurringEntryRunner interface {
	// AddRecurringEntry adds a new recurring entry.
	AddRecurringEntry(t db.Transaction, entry *fin.RecurringEntry) error
}

type AddUserRunner

type AddUserRunner interface {
	// AddUser adds a new user.
	AddUser(t db.Transaction, user *fin.User) error
}

type DoEntryChangesRunner

type DoEntryChangesRunner interface {
	// DoEntryChanges adds, updates, and deletes entries in bulk.
	DoEntryChanges(t db.Transaction, changes *EntryChanges) error
}

type EntriesByAccountIdRunner

type EntriesByAccountIdRunner interface {
	// EntryByAccountId gets entries by account from most to least recent.
	// acctId is the account ID; account is where
	// Account object is stored; consumer consumes the fin.EntryBalance
	// values.
	EntriesByAccountId(t db.Transaction, acctId int64,
		account *fin.Account, consumer goconsume.Consumer) error
}

type EntriesRunner

type EntriesRunner interface {
	// Entries gets entries from most to least recent.
	// options is additional options for getting entries, may be nil;
	// consumer consumes the fin.Entry values.
	Entries(t db.Transaction, options *EntryListOptions,
		consumer goconsume.Consumer) error
}

type EntryByIdRunner

type EntryByIdRunner interface {
	// EntryById fetches an Entry by id.
	EntryById(t db.Transaction, id int64, entry *fin.Entry) error
}

type EntryChanges

type EntryChanges struct {
	// Adds is entries to add
	Adds []*fin.Entry
	// The key is the entry id; the value does the update in-place.
	Updates map[int64]fin.EntryUpdater
	// Deletes is the ids of the entries to delete.
	Deletes []int64
	// Etags contains the etags of the entries being updated.
	// It is used to detect concurrent updates.
	// The key is the entry id; the value is the etag of the original entry.
	// This field is optional, but if present it must contain the etag of
	// each entry being updated.
	Etags map[int64]uint64
}

EntryChanges represents changes to entries.

type EntryListOptions

type EntryListOptions struct {
	// If set, entries listed are on or after this date.
	Start *time.Time
	// If set, entries listed are before this date
	End *time.Time
	// If true, show only unreviewed entries
	Unreviewed bool
}

EntryListOptions represents options to list entries.

type NoPermissionStore

type NoPermissionStore struct {
}

NoPermissionStore always returns NoPermissionError

func (NoPermissionStore) AccountById

func (n NoPermissionStore) AccountById(
	t db.Transaction, acctId int64, account *fin.Account) error

func (NoPermissionStore) Accounts

func (n NoPermissionStore) Accounts(
	t db.Transaction, consumer goconsume.Consumer) error

func (NoPermissionStore) ActiveAccounts

func (n NoPermissionStore) ActiveAccounts(
	t db.Transaction) (accounts []*fin.Account, err error)

func (NoPermissionStore) AddAccount

func (n NoPermissionStore) AddAccount(
	t db.Transaction, Account *fin.Account) error

func (NoPermissionStore) AddRecurringEntry

func (n NoPermissionStore) AddRecurringEntry(
	t db.Transaction, entry *fin.RecurringEntry) error

func (NoPermissionStore) AddUser

func (n NoPermissionStore) AddUser(t db.Transaction, user *fin.User) error

func (NoPermissionStore) DoEntryChanges

func (n NoPermissionStore) DoEntryChanges(
	t db.Transaction, changes *EntryChanges) error

func (NoPermissionStore) Entries

func (n NoPermissionStore) Entries(t db.Transaction, options *EntryListOptions,
	consumer goconsume.Consumer) error

func (NoPermissionStore) EntriesByAccountId

func (n NoPermissionStore) EntriesByAccountId(t db.Transaction, acctId int64,
	account *fin.Account, consumer goconsume.Consumer) error

func (NoPermissionStore) EntryById

func (n NoPermissionStore) EntryById(
	t db.Transaction, id int64, entry *fin.Entry) error

func (NoPermissionStore) RecurringEntries

func (n NoPermissionStore) RecurringEntries(
	t db.Transaction, consumer goconsume.Consumer) error

func (NoPermissionStore) RecurringEntryById

func (n NoPermissionStore) RecurringEntryById(
	t db.Transaction, id int64, entry *fin.RecurringEntry) error

func (NoPermissionStore) RemoveAccount

func (n NoPermissionStore) RemoveAccount(
	t db.Transaction, accountId int64) error

func (NoPermissionStore) RemoveRecurringEntryById

func (n NoPermissionStore) RemoveRecurringEntryById(
	t db.Transaction, id int64) error

func (NoPermissionStore) RemoveUserByName

func (n NoPermissionStore) RemoveUserByName(t db.Transaction, name string) error

func (NoPermissionStore) UnreconciledEntries

func (n NoPermissionStore) UnreconciledEntries(
	t db.Transaction, acctId int64, account *fin.Account,
	consumer goconsume.Consumer) error

func (NoPermissionStore) UpdateAccount

func (n NoPermissionStore) UpdateAccount(
	t db.Transaction, account *fin.Account) error

func (NoPermissionStore) UpdateAccountImportSD

func (n NoPermissionStore) UpdateAccountImportSD(
	t db.Transaction, accountId int64, date time.Time) error

func (NoPermissionStore) UpdateRecurringEntry

func (n NoPermissionStore) UpdateRecurringEntry(
	t db.Transaction, entry *fin.RecurringEntry) error

func (NoPermissionStore) UpdateUser

func (n NoPermissionStore) UpdateUser(t db.Transaction, user *fin.User) error

func (NoPermissionStore) UserById

func (n NoPermissionStore) UserById(t db.Transaction, id int64, user *fin.User) error

func (NoPermissionStore) UserByName

func (n NoPermissionStore) UserByName(t db.Transaction, name string, user *fin.User) error

func (NoPermissionStore) Users

func (n NoPermissionStore) Users(t db.Transaction, consumer goconsume.Consumer) error

type RecurringEntriesRunner

type RecurringEntriesRunner interface {
	// RecurringEntries gets all the recurring entries sorted by date
	// in ascending order.
	RecurringEntries(t db.Transaction, consumer goconsume.Consumer) error
}

type RecurringEntryByIdRunner

type RecurringEntryByIdRunner interface {
	// RecurringEntryById gets a recurring entry by id.
	RecurringEntryById(
		t db.Transaction, id int64, entry *fin.RecurringEntry) error
}

type RecurringEntrySkipper

type RecurringEntrySkipper interface {
	RecurringEntryByIdRunner
	UpdateRecurringEntryRunner
}

type RemoveAccountRunner

type RemoveAccountRunner interface {
	// RemoveAccount removes an account.
	RemoveAccount(t db.Transaction, accountId int64) error
}

type RemoveRecurringEntryByIdRunner

type RemoveRecurringEntryByIdRunner interface {
	// RemoveRecurringEntryById removes a recurring entry by id.
	RemoveRecurringEntryById(t db.Transaction, id int64) error
}

type RemoveUserByNameRunner

type RemoveUserByNameRunner interface {
	// RemoveUserByName removes a user by name.
	RemoveUserByName(t db.Transaction, name string) error
}

type UnreconciledEntriesRunner

type UnreconciledEntriesRunner interface {
	// UnreconciledEntries gets unreconciled entries by account from most to least
	// recent.
	// acctId is the account ID; account, which can be nil, is where
	// Account object is stored; consumer consumes the fin.Entry values
	UnreconciledEntries(t db.Transaction, acctId int64,
		account *fin.Account, consumer goconsume.Consumer) error
}

type UpdateAccountImportSDRunner

type UpdateAccountImportSDRunner interface {
	// UpdateAccountImportSD updates the import start date of an account.
	UpdateAccountImportSD(
		t db.Transaction, accountId int64, date time.Time) error
}

type UpdateAccountRunner

type UpdateAccountRunner interface {
	// UpdateAccount updates an account.
	UpdateAccount(
		t db.Transaction, account *fin.Account) error
}

type UpdateRecurringEntryRunner

type UpdateRecurringEntryRunner interface {
	// UpdateRecurringEntry updates a recurring entry.
	UpdateRecurringEntry(t db.Transaction, entry *fin.RecurringEntry) error
}

type UpdateUserByNameRunner

type UpdateUserByNameRunner interface {
	UserByNameRunner
	UpdateUserRunner
}

type UpdateUserRunner

type UpdateUserRunner interface {
	// UpdateUser updates a user.
	UpdateUser(t db.Transaction, user *fin.User) error
}

type UserByIdRunner

type UserByIdRunner interface {
	// UserById gets a user by id.
	UserById(t db.Transaction, id int64, user *fin.User) error
}

type UserByNameRunner

type UserByNameRunner interface {
	// UserByName gets a user by name.
	UserByName(t db.Transaction, name string, user *fin.User) error
}

type UsersRunner

type UsersRunner interface {
	//Users gets all the users sorted by user name.
	Users(t db.Transaction, consumer goconsume.Consumer) error
}

Directories

Path Synopsis
Package fixture provides test suites to test implementations of the interfaces in the findb package.
Package fixture provides test suites to test implementations of the interfaces in the findb package.
Package for_sqlite stores types in fin package in a sqlite database.
Package for_sqlite stores types in fin package in a sqlite database.
Package sqlite_setup sets up a sqlite database for personal finance.
Package sqlite_setup sets up a sqlite database for personal finance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL