financedatabase

package
v0.0.0-...-c9bcc8e Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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 Close

func Close()

Close the connection with the databse

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:

  1. it has to be possible to reconnect the databse if the connection is lost
  2. it has to be possible to try a new connection to the database if a failure occours
  3. 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

func (Amount) GetStart

func (a Amount) GetStart() (year int, month int, day int)

GetStart returns the year, month and day of the starting date

func (Amount) String

func (a Amount) String() string

String returns a string with all the data contained in the amount

type Categories

type Categories []Category

Categories is a collection (slice) of Category

func (*Categories) Add

func (ca *Categories) Add(c string)

Add a category to the table Categories

func (*Categories) Delete

func (ca *Categories) Delete(c Category)

Delete a category from the table Categories

func (*Categories) GetAll

func (ca *Categories) GetAll()

GetAll return all the categories

type Category

type Category string

Category rapresent a row in the Categories table

func (Category) Equals

func (c Category) Equals(c2 Category) bool

Equals checks that two categories are the same

func (Category) String

func (c Category) String() string

String returns the name of the category

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

func (e Expence) EqualValue(a Amount) bool

EqualValue checks if the have the same amount They might be different Expences

func (Expence) Equals

func (e Expence) Equals(e2 Found) bool

Equals checks if the id and the values are the same The id is never set manually, is given by the database

func (Expence) GetAmount

func (e Expence) GetAmount() Amount

GetAmount returns the struct Amount of the Expence

func (Expence) String

func (e Expence) String() string

String return a string containing the id and the string of Amount

func (Expence) Update

func (e Expence) Update(a Amount)

Update allows to modify the expence Can only be called on an existing Exence (already extracted from 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) Add

func (ex Expences) Add(a Amount)

Add adds an Expence to the database

func (Expences) Delete

func (ex Expences) Delete(e Found)

Delete an Expence from the db and the struct

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

func (ex Expences) GetElement(i int) Found

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

func (Expences) Len

func (ex Expences) Len() int

Len return the number of Expence in Expences

func (Expences) String

func (ex Expences) String() string

String returns a string containing all the string of all the Expence contained in the struct

func (Expences) Sum

func (ex Expences) Sum() float32

Sum return the sum of all the Expence in Expences

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

func (s Saving) EqualValue(s2 Amount) bool

EqualValue checks if the have the same amount They might be different Expences

func (Saving) Equals

func (s Saving) Equals(s2 Found) bool

Equals checks if the id and the values are the same The id is never set manually, is given by the database

func (Saving) GetAmount

func (s Saving) GetAmount() Amount

GetAmount returns the struct Amount of the Saving

func (Saving) String

func (s Saving) String() string

String return a string containing the id and the string of Amount

func (Saving) Update

func (s Saving) Update(a Amount)

Update allows to modify the saving Can only be called on an existing Saving (already extracted from 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) Add

func (sa Savings) Add(a Amount)

Add adds a Saving to the database

func (Savings) Delete

func (sa Savings) Delete(s Found)

Delete a Saving from the db and the struct

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

func (sa Savings) GetElement(i int) Found

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

func (Savings) Len

func (sa Savings) Len() int

Len return the number of Saving in Savings

func (Savings) String

func (sa Savings) String() string

String returns a string containing all the string of all the Saving contained in the struct

func (Savings) Sum

func (sa Savings) Sum() float32

Sum return the sum of all the Saving in Savings

Jump to

Keyboard shortcuts

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