Documentation ¶
Index ¶
- Variables
- func Close()
- func InitDB(name string)
- type Amount
- type Categories
- type Category
- type Expence
- type Expences
- func (ex Expences) Add(a Amount)
- func (ex Expences) Delete(e Found)
- func (ex Expences) GetAll()
- func (ex Expences) GetElement(i int) Found
- func (ex Expences) GetNonRecurrent()
- func (ex Expences) GetRecurrent()
- func (ex Expences) Len() int
- func (ex Expences) String() string
- func (ex Expences) Sum() float32
- type Found
- type Founds
- type Saving
- type Savings
Constants ¶
This section is empty.
Variables ¶
var ExpencesNames = map[string]string{
"item": "expence",
"table": "expences",
}
ExpencesNames is a set of names that assure consistency Make it esier to change names when the database is modified
var SavingsNames = map[string]string{
"item": "saving",
"table": "savings",
}
SavingsNames is a set of names that assure consistency Make it esier to change names when the database is modified
Functions ¶
func InitDB ¶
func InitDB(name string)
InitDB makes the necessaries initialization to use the database, whithout launching this function, the db cannot work Those steps have been seprated from the init() because:
- it has to be possible to reconnect the databse if the connection is lost
- it has to be possible to try a new connection to the database if a failure occours
- both operation have to be avaliable even to the main
if the name is an empty string "" the default db name will be finance.db
Types ¶
type Amount ¶
type Amount struct {
// contains filtered or unexported fields
}
Amount is a collection of data about a movement of money It rapresent a row in bothe the table Expences and Savings Amount contain the basic data needed by both Expences and Savings, where:
Expences move money outside of the money pool Savings move money inside of the money pool
func (*Amount) Constructor ¶
func (a *Amount) Constructor(name string, sum float32, start string, end string, category string, recurrency int)
Constructor fills the struct Amount imposing the constraint the data has to follow
type Categories ¶
type Categories []Category
Categories is a collection (slice) of Category
func (*Categories) Delete ¶
func (ca *Categories) Delete(c Category)
Delete a category from the table Categories
type Category ¶
type Category string
Category rapresent a row in the Categories table
type Expence ¶
type Expence struct {
// contains filtered or unexported fields
}
Expence are stored in the database as a row containing and id and a series of data rapresented by the struct Amount
func (Expence) EqualValue ¶
EqualValue checks if the have the same amount They might be different Expences
func (Expence) Equals ¶
Equals checks if the id and the values are the same The id is never set manually, is given by the database
type Expences ¶
type Expences struct {
// contains filtered or unexported fields
}
Expences is a collection (slice) of Expence
func NewExpences ¶
func NewExpences() Expences
NewExpences create a new Expences struct Slices need initialization
func (Expences) GetAll ¶
func (ex Expences) GetAll()
GetAll fill Expences with all the Expence contained in the database Ordered by most recent to eldest
func (Expences) GetElement ¶
GetElement returns the Expence at the specified position
func (Expences) GetNonRecurrent ¶
func (ex Expences) GetNonRecurrent()
GetNonRecurrent fill Expences with all the non recurring Expence
func (Expences) GetRecurrent ¶
func (ex Expences) GetRecurrent()
GetRecurrent fill Expences with all the recurring Expence
type Found ¶
type Found interface { // Equals two Expence/Saving by id and value Equals(Found) bool // Equals the Amount contained in two Expence/Saving EqualValue(Amount) bool // Update the values of the Amount of the Found and the database Update(Amount) // GetAmount returns the Amount of the Expence/Saving GetAmount() Amount // String returns a sctring containing id and values String() string // contains filtered or unexported methods }
Found define the intefaces for both Expence and Saving
type Founds ¶
type Founds interface { // GetAll loads all the Expence/Saving in the DB GetAll() // GetRecurrent loads all the Expence/Saving in the DB, that are recurring GetRecurrent() // GetNonRecurrent loads all the Expence/Saving in the DB, that are non recurring GetNonRecurrent() // Len returns how many Found are in Founds Len() int // GetElement return a single Found a the specified position GetElement(int) Found // Add an Expence/Saving to the databade but not to the slice // The slice is not update since it's uncertain if the Expence/Saving belongs to that collection of Saving/Expence Add(Amount) // Delete and Expence/Saving from the database and the struct Delete(Found) // Sum all the Expence/saving values contained in the struct Sum() float32 // String returns a string with all the strings of each Expence/Saving contained in the struct String() string // contains filtered or unexported methods }
Founds interfaces to manage group of Expences and Savings
type Saving ¶
type Saving struct {
// contains filtered or unexported fields
}
Saving are stored in the database as a row containing and id and a series of data rapresented by the struct Amount
func (Saving) EqualValue ¶
EqualValue checks if the have the same amount They might be different Expences
func (Saving) Equals ¶
Equals checks if the id and the values are the same The id is never set manually, is given by the database
type Savings ¶
type Savings struct {
// contains filtered or unexported fields
}
Savings is a collection (slice) of Saving
func NewSavings ¶
func NewSavings() Savings
NewSavings create a new Savings struct Slices need initialization
func (Savings) GetAll ¶
func (sa Savings) GetAll()
GetAll fill Expences with all the Saving contained in the database Ordered by most recent to eldest
func (Savings) GetElement ¶
GetElement returns the Expence at the specified position
func (Savings) GetNonRecurrent ¶
func (sa Savings) GetNonRecurrent()
GetNonRecurrent fill Savings with all the non recurring Saving
func (Savings) GetRecurrent ¶
func (sa Savings) GetRecurrent()
GetRecurrent fill Savings with all the recurring Saving